There are many similar questions posted already, but I've already tried those solutions to no avail. I'm working through a basic Django tutorial, and here is my code:
urls.py
from django.conf.urls import patterns, include, urlfrom django.contrib import admin
admin.autodiscover()urlpatterns = patterns('',# Examples:# url(r'^$', 'tango_with_django_project.views.home', name='home'),# url(r'^tango_with_django_project/', include('tango_with_django_project.foo.urls')),# Uncomment the admin/doc line below to enable admin documentation:url(r'^admin/doc/', include('django.contrib.admindocs.urls')),# Uncomment the next line to enable the admin:url(r'^admin/', include(admin.site.urls)),url(r'^rango/', include('rango.urls')), # ADD THIS NEW TUPLE!
)
views.py
from django.http import HttpResponsedef index(request):return HttpResponse("Rango says hello world!")
From the settings.py file
ROOT_URLCONF = 'tango_with_django_project.urls'
Hope you all can help get me started
Let's say I have a Django project called FailBook, with two apps, posts and links. If I look into FailBook/urls.py, I will find something like
from django.conf.urls import patterns, include, urlfrom django.contrib import admin
admin.autodiscover()urlpatterns = patterns('',url(r'^admin/', include(admin.site.urls)),url(r'^posts/', include('posts.urls')), ## Custom url includeurl(r'^links/', include('links.urls')), ## Custom url include
)
So then, when you look into the directory structure, you will notice that there are extra two urls.py files
FailBook
|-- posts|-- models.py|-- urls.py|-- views.py|-- etc.
|-- links|-- models.py|-- urls.py|-- views.py|-- etc.# urls.py file in the posts folder
from django.conf.urls import patterns, include, url
from .views import PostListView, PostDetailViewurlpatterns = patterns('',url(r'^posts/', PostListView.as_view()), url(r'^posts/(?P<post_id>\d+)', PostDetailView.as_view()),
)
# where both views are class based views, hence the as_view function call