Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Django Url赢得';不匹配_Regex_Django_Url Pattern - Fatal编程技术网

Regex Django Url赢得';不匹配

Regex Django Url赢得';不匹配,regex,django,url-pattern,Regex,Django,Url Pattern,我有不匹配的URL模式。这是我根据Django教程改编的。这可能很简单,但我只是错过了 错误: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/sendemail/1 Using the URLconf defined in emailme.urls, Django tried these URL patterns, in this order: 1. ^send

我有不匹配的URL模式。这是我根据Django教程改编的。这可能很简单,但我只是错过了

错误:

Page not found (404)
    Request Method: GET
    Request URL:    http://127.0.0.1:8000/sendemail/1
Using the URLconf defined in emailme.urls, Django tried these URL patterns, in this order:
    1. ^sendemail ^$ [name='index']
    2. ^sendemail ^(?P<msg_id>\d+)/$ [name='detail']
    3. ^sendemail ^(?P<msg_id>\d+)/results/$ [name='results']
    4. ^admin/
The current URL, sendemail/1, didn't match any of these.
根URL.py:

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^sendemail', include('sendemail.urls')),
    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)
URL.py:

from django.conf.urls import patterns, url
from 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'))

您要使用的模式需要一个尾随斜杠

url(r'^(?P<msg_id>\d+)/$', views.detail, name='detail'),
url(r'^(?P\d+/$),views.detail,name='detail'),

您正在使用的URL,
sendmail/1
,没有。能否显示您的根URL配置?将
URL(r'^sendmail',include('sendmail.URL'),
更改为
URL(r'^sendmail/',include('sendmail.URL'),
Yep!这就解决了问题。谢谢
from django.http import HttpResponse

def index(request):
    return HttpResponse("You're at the 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)
url(r'^(?P<msg_id>\d+)/$', views.detail, name='detail'),