regex - Django urlpatterns won't match -
i have urlpatterns aren't matching. i'm adapting django tutorial. it's easy, i'm missing it.
the error:
page not found (404) request method: request url: http://127.0.0.1:8000/sendemail/1 using urlconf defined in emailme.urls, django tried these url patterns, in order: 1. ^sendemail ^$ [name='index'] 2. ^sendemail ^(?p<msg_id>\d+)/$ [name='detail'] 3. ^sendemail ^(?p<msg_id>\d+)/results/$ [name='results'] 4. ^admin/ current url, sendemail/1, didn't match of these.
models.py:
from django.db import models class choice(models.model): choice_text = models.charfield(max_length=200) def __unicode__(self): return self.choice_text
root urls.py:
from django.conf.urls import patterns, include, url # uncomment next 2 lines enable admin: django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^sendemail', include('sendemail.urls')), # uncomment next line enable admin: url(r'^admin/', include(admin.site.urls)), )
urls.py:
from django.conf.urls import patterns, url sendemail import views urlpatterns = patterns('', url(r'^$', views.index, name='index'), url(r'^(?p<msg_id>\d+)/$', views.detail, name='detail'), url(r'^(?p<msg_id>\d+)/results/$', views.results, name='results'))
views.py:
from django.http import httpresponse def index(request): return httpresponse("you're @ index") def detail(request, msg_id): return httpresponse("the details of message id %s" % msg_id) def results(request, msg_id): return httpresponse("the results of message id %s" % msg_id)
this pattern, 1 you're going for, requires trailing slash.
url(r'^(?p<msg_id>\d+)/$', views.detail, name='detail'),
the url you're using, sendemail/1
, doesn't have one.
Comments
Post a Comment