TypeError: url() got an unexpected keyword argument 'name_space'
TypeError: url() got an unexpected keyword argument 'name_space'
我知道这看起来是个简单的问题,但我还是个新手,无法自己解决,所以:
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'),
]
之前我有以下错误,所以我删除了包含函数
ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
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
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')
我正在使用 Django 2.0 和 Python 3.6.1
你能告诉我为什么我得到 TypeError with name_space arg,这与 Django 版本有关,非常感谢。
你想要的参数很可能是name
而不是name_space
url(r'', 'learning_logs.urls', name='learning_logs')
您应该使用 include()
来包含来自另一个 urls.py
的 url 模式
url(r'', include('learning_logs.urls')),
没有带下划线的 name_space
参数。 include()
函数接受 namespace
。但是,正如错误消息所建议的那样,您应该在包含的 urls.py
中设置 app_name
而不是使用 namespace
。您不需要使用 namespace
除非您多次包含相同的网址。
from . import views
app_name = 'learning_logs'
urlpatterns=[
#Homepage
url(r'^$',views.index,name='index'),
]
我知道这看起来是个简单的问题,但我还是个新手,无法自己解决,所以:
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'),
]
之前我有以下错误,所以我删除了包含函数
ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
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
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')
我正在使用 Django 2.0 和 Python 3.6.1
你能告诉我为什么我得到 TypeError with name_space arg,这与 Django 版本有关,非常感谢。
你想要的参数很可能是name
而不是name_space
url(r'', 'learning_logs.urls', name='learning_logs')
您应该使用 include()
来包含来自另一个 urls.py
url(r'', include('learning_logs.urls')),
没有带下划线的 name_space
参数。 include()
函数接受 namespace
。但是,正如错误消息所建议的那样,您应该在包含的 urls.py
中设置 app_name
而不是使用 namespace
。您不需要使用 namespace
除非您多次包含相同的网址。
from . import views
app_name = 'learning_logs'
urlpatterns=[
#Homepage
url(r'^$',views.index,name='index'),
]