Django - LOCALHOST missing despite other views working
<p><strong>BACKGROUND</strong>:</p>

<p>Worked through Django's tutorial and created multiple views:</p>

<ul>
<li>/admin</li>
<li>/app</li>
</ul>

<p>Currently having issues with "localhost:8000" despite localhost/app and localhost/admin views working (see below):</p>

<p><strong>CODE</strong></p>

<p><strong>Folder Structure (virtualenv):</strong></p>

<pre><code>main/
   db.sqlite3
   manage.py
   app/
      _init_.py
      admin.py
      apps.py
      models.py
      tests.py
      views.py
      urls.py
      migrations/
         _init.py

   main/
      _init_.py
      settings.py
      urls.py
      wsgipy
</code></pre>

<p><em>../main/app/views.py:</em></p>

<pre><code>from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, world. You're at the app index.")
</code></pre>

<p><em>../main/app/urls.py:</em></p>

<pre><code>from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
]
</code></pre>

<p><em>../main/main/urls.py:</em></p>

<pre><code>from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^app/', include('app.urls')),
]
</code></pre>

<p><strong>ISSUES/QUESTIONS:</strong></p>

<ol>
<li>localhost/app or localhost/admin shows a rendered page. However, "localhost:8000" does not show the original, django landing page (despite it working before). What am I missing?</li>
<li>Do you recommend any other folder structure? From my understanding, it's poor-form to put /main/main in the location that it currently is. Do you have recommendations on a new folder structure?</li>
</ol>

<p><code>../main/main/urls.py</code> is your entry point for defining your URL patterns and you have no pattern defined to handle <code>/</code> which is what <code>localhost:8000</code> would be in this case.  You have two basic options.</p>

<p>First, if you want the stuff in <code>../main/app</code> to have a URL that includes <code>/app/</code> you need to define the URL patterns that will exist at the root level.  Start by creating a view function for the root URL and add a URL pattern for <code>/</code>, see below:</p>

<p><em>../main/main/views.py</em></p>

<pre><code>from django.http import HttpResponse

def index(request):
    return HttpResponse("This is the home page/site root")
</code></pre>

<p><em>../main/main/urls.py</em></p>

<pre><code>from django.conf.urls import include, url
from django.contrib import admin
from . import views

urlpatterns = [
    url(r'^$', ), views.index, name='home',
    url(r'^admin/', admin.site.urls),
    url(r'^app/', include('app.urls')),
]
</code></pre>

<p>Second option, if you want the views in <code>../main/app/</code> to exist under the root URL (<code>/</code> instead of <code>/app/</code>) then just change the base of the imported <code>app</code> URL patterns in <code>../main/main/urls.py</code>:</p>

<p><em>../main/main/urls.py</em></p>

<pre><code>from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^/', include('app.urls')),
]
</code></pre>

<p>There is nothing wrong with your folder structure.  There are certainly other layouts you could use for your project, but what you are using is Django's default out of the box layout.  Unless you have a specific reason to use a different layout, stick with what you have.  Spend your time learning more about Django, worry about trying to optimize your project layout when you have a better understanding of how Django's pieces all fit together.</p>

<p>I think what you need to consider is what you want your site's URLS to look like, then build the layout around that. You don't need the <code>app</code> app unless you want to organize your code that way.  As a starting point you can just put everything you have in the <code>app</code> app under <code>main</code> and expand out to other apps as it makes sense for the project.</p>

python django