gpt4 book ai didi

Django 1.9 url 包含 AttributeError 'str' 对象没有属性 'regex'

转载 作者:行者123 更新时间:2023-12-01 23:30:55 25 4
gpt4 key购买 nike

我最近从 Django 1.7 升级到 1.9,并且在使用 include 转换 url 时遇到了一些问题。

我收到错误消息:AttributeError: 'str' object has no attribute 'regex'

urls.py 文件如下:

myapp/urls.py:

from django.conf.urls import url

from myapp.views import IndexView

#app_name = 'myapp'

urlpatterns = [
url(r'^$', IndexView.as_view(), name='index'),
]

mysite/urls.py:

from django.conf.urls import url, include

urlpatterns = [
url(r'^myapp/', include('myapp.urls')),

# Have also tried the following combinations
#url(r'^myapp/', include('myapp.urls', 'myapp')),
#url(r'^myapp/', include('myapp.urls'), name='myapp'),

# This one works
url(r'^admin/', admin.site.urls),
]

完整堆栈跟踪:

Traceback (most recent call last):
File "mysite/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "lib/python3.5/site-packages/Django-1.9.1-py3.5.egg/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "lib/python3.5/site-packages/Django-1.9.1-py3.5.egg/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "lib/python3.5/site-packages/Django-1.9.1-py3.5.egg/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "lib/python3.5/site-packages/Django-1.9.1-py3.5.egg/django/core/management/base.py", line 398, in execute
self.check()
File "lib/python3.5/site-packages/Django-1.9.1-py3.5.egg/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "lib/python3.5/site-packages/Django-1.9.1-py3.5.egg/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "lib/python3.5/site-packages/Django-1.9.1-py3.5.egg/django/core/checks/urls.py", line 10, in check_url_config
return check_resolver(resolver)
File "lib/python3.5/site-packages/Django-1.9.1-py3.5.egg/django/core/checks/urls.py", line 23, in check_resolver
warnings.extend(check_resolver(pattern))
File "lib/python3.5/site-packages/Django-1.9.1-py3.5.egg/django/core/checks/urls.py", line 27, in check_resolver
warnings.extend(check_pattern_startswith_slash(pattern))
File "lib/python3.5/site-packages/Django-1.9.1-py3.5.egg/django/core/checks/urls.py", line 63, in check_pattern_startswith_slash
regex_pattern = pattern.regex.pattern
AttributeError: 'str' object has no attribute 'regex'

最佳答案

你不应该在这里导入 include from django.conf.urls import url, include 吗?我的意思是,我认为您应该使用 include,而不是使用 import

关于Django 1.9 url 包含 AttributeError 'str' 对象没有属性 'regex',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36288146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com