[英]TypeError: url() got an unexpected keyword argument 'name_space'
I know it looks like a simple problem but I'm still too new for sorting it out myself, so : 我知道它看起来像一个简单的问题,但我仍然太新了自己整理出来,所以:
learning_log/urls.py learning_log / urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'', 'learning_logs.urls',name_space='learning_logs'),
]
Previously I had the following error so I've removed the include function 以前我有以下错误,所以我删除了包含功能
ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported.
ImproperlyConfigured:不支持在include()中指定名称空间而不提供app_name。 Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
在包含的模块中设置app_name属性,或者传递包含模式列表和app_name的2元组。
learing_logs/urls.py learing_logs / urls.py
"""Defines URL patterns for learning_logs."""
from django.conf.urls import url
from . import views
urlpatterns=[
#Homepage
url(r'^$',views.index,name='index'),
]
views.py views.py
from django.shortcuts import render
#Create your views here.
def index(request):
"""The home page for Learning Log"""
return render(request,'learning_logs/index.html')
I'm using Django 2.0 and Python 3.6.1 我正在使用Django 2.0和Python 3.6.1
Could you please advise why I'm getting TypeError with name_space arg, is that related to Django version, many thanks in advance. 你能否告诉我为什么我得到带有name_space arg的TypeError,这与Django版本有关,非常感谢提前。
You should use include()
to include urls patterns from another urls.py
您应该使用
include()
来包含来自另一个urls.py
urls模式
url(r'', include('learning_logs.urls')),
There is no name_space
argument with an underscore. 没有带有下划线的
name_space
参数。 The include()
function accepts namespace
. include()
函数接受namespace
。 However, as the error message suggests, you should set app_name
in the included urls.py
instead of using namespace
. 但是,正如错误消息所示,您应该在包含的
urls.py
设置app_name
,而不是使用namespace
。 You don't need to use namespace
unless you are including the same urls multiple times. 除非您多次包含相同的URL,否则不需要使用
namespace
。
from . import views
app_name = 'learning_logs'
urlpatterns=[
#Homepage
url(r'^$',views.index,name='index'),
]
The parameter you want is likely name
not name_space
你想要的参数很可能
name
不name_space
url(r'', 'learning_logs.urls', name='learning_logs')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.