python - Can't get django urls to work -
i've got simple django setup in have 1 app called 'lists'. want http://127.0.0.1:8000/lists
show app. changed main urls.py following:
from django.conf.urls import patterns, include, url django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^lists/', include('lists.urls')), url(r'^admin/', include(admin.site.urls)), )
and changed urls.py resides in lists-folder (my app called lists) following:
from django.conf.urls import patterns, url lists import views urlpatterns = patterns( url(r'^$', views.index, name='index') )
as far know following instructions in the django tutorial well, when visit http://127.0.0.1:8000/lists
(without trailing slash) gives me following error:
page not found (404) request method: request url: http://127.0.0.1:8000/lists using urlconf defined in companylists.urls, django tried these url patterns, in order: ^lists/ ^admin/ current url, lists, didn't match of these.
and when visit http://127.0.0.1:8000/lists/
(with trailing slash) gives me following error:
page not found (404) request method: request url: http://127.0.0.1:8000/lists/ using urlconf defined in companylists.urls, django tried these url patterns, in order: ^admin/ current url, lists/, didn't match of these.
i don't understand why doesn't search ^lists/ anymore when visit url trailing slash. know doing wrong here?
all tips welcome!
you're missing empty string @ start of patterns
in lists urls.py
.
try this:
urlpatterns = patterns('', url(r'^$', views.index, name='index') )
the blank string view prefix can use assist dry principal. used prefix views path.
for example, (extending example above):
rather having:
urlpatterns = patterns('', url(r'^$', views.index, name='index'), url(r'^homepage$', views.homepage, name='index'), url(r'^lists$', views.lists, name='index'), url(r'^detail$', views.detail, name='index'), )
you can use:
urlpatterns = patterns('views', url(r'^$', index, name='index'), url(r'^homepage$', homepage, name='index'), url(r'^lists$', lists, name='index'), url(r'^detail$', detail, name='index'), )
to have multiple view prefixes segment urlpatterns
.
urlpatterns = patterns('views', url(r'^$', index, name='index'), url(r'^homepage$', homepage, name='index'), url(r'^lists$', lists, name='index'), url(r'^detail$', detail, name='index'), ) urlpatterns += patterns('more_views', url(r'^extra_page$', extra_page, name='index'), url(r'^more_stuff$', something_else, name='index'), )
Comments
Post a Comment