Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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
Django 诺维塞马奇/_Django - Fatal编程技术网

Django 诺维塞马奇/

Django 诺维塞马奇/,django,Django,我正在尝试创建非常有意义的URL,但我想我做错了 这项工作: from django.conf.urls.defaults import patterns, url from places.views import explore_view urlpatterns = patterns('', url(r'', explore_view, name='explore'), ) 这并不是: from django.conf.urls.defaults import patterns,

我正在尝试创建非常有意义的URL,但我想我做错了

这项工作:

from django.conf.urls.defaults import patterns, url
from places.views import explore_view

urlpatterns = patterns('',
    url(r'', explore_view, name='explore'),
)
这并不是:

from django.conf.urls.defaults import patterns, url
from places.views import explore_view

urlpatterns = patterns('',
    url(r'(?P<countryorcategory>[0-9A-Za-z._%+-]+)', explore_view, name='explore'),
)

我假设您使用的模板如下所示:

 {% url 'explore' argument %}
此错误可能意味着
参数未设置为任何值。

此行:

url(r'(?P<countryorcategory>[0-9A-Za-z._%+-]+)', explore_view, name='explore')
如果要继续使用具有相同名称的非参数URL,可以定义具有相同名称但具有不同模式的其他URL。例如:

urlpatterns = patterns('',
    url(r'(?P<countryorcategory>[0-9A-Za-z._%+-]+)', explore_view, name='explore'),
    url(r'', explore_view, name='explore'),
)
urlpatterns=patterns(“”,
url(r'(?P[0-9A-Za-z.u%+-]+),explore_view,name='explore'),
url(r“”,explore_视图,name='explore'),
)

然后,
{%url'explore'%}
应该可以使用参数,也可以不使用参数。

对于我来说,我忘记了路由的名称空间。而不是

{% url 'login' %}
我应该写信的

{% url 'accounts:login' %}
使用此配置:

# root URLs
url(r'^accounts/', include('myproject.accounts.accounts.urls', namespace='accounts'))

# accounts URLs
url(r'^login$', views.login, name='login')

发布模板main.html。
{% url 'accounts:login' %}
# root URLs
url(r'^accounts/', include('myproject.accounts.accounts.urls', namespace='accounts'))

# accounts URLs
url(r'^login$', views.login, name='login')