简体   繁体   English

TypeError:url()得到一个意外的关键字参数'name_space'

[英]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 你想要的参数很可能namename_space

url(r'', 'learning_logs.urls', name='learning_logs')

(Django 2.0 url() Docs) (Django 2.0 url() Docs)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:得到了意外的关键字参数“ name” - TypeError: got an unexpected keyword argument “name” 类型错误:Planet() 有一个意外的关键字参数“名称” - TypeError: Planet() got an unexpected keyword argument 'name' Python TypeError: got an unexpected keyword argument 'name' - Python TypeError: got an unexpected keyword argument 'name' / Accept() 处的 TypeError 得到了意外的关键字参数“名称” - TypeError at / Accept() got an unexpected keyword argument 'name' TypeError:得到一个意外的关键字参数 - TypeError: got an unexpected keyword argument 类型错误:__init__() 得到了意外的关键字参数“名称”-CONVOKIT - TypeError: __init__() got an unexpected keyword argument 'name' - CONVOKIT Keras: TypeError: __call__() 得到了一个意外的关键字参数“name” - Keras: TypeError: __call__() got an unexpected keyword argument 'name' 错误-TypeError在Django中获得了意外的关键字参数'name' - Error - TypeError got an unexpected keyword argument 'name' in django Django TypeError: get() 得到了一个意外的关键字参数“quiz_name” - Django TypeError: get() got an unexpected keyword argument 'quiz_name' TypeError: contact() 在使用 flask 时得到了一个意外的关键字参数“名称” - TypeError: contact() got an unexpected keyword argument 'name' while using flask
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM