Django URLResolver 错误
Django URLResolver error
我正在尝试使用 IIS 使用 wfastcgi 在 windows 服务器上托管 Django 应用程序。
使用 django-admin.py startproject foo
创建新的 django 项目后,当我 运行 使用 django 服务器 python manage.py runserver
管理页面时,管理页面打开正常 python manage.py runserver
。
然而,当我尝试通过 127.0.0.1/foo 访问它时,出现 Django 404 错误:
Using the URLconf defined in foo.urls, Django tried these URL patterns, in this order:
admin/
The current path, foo, didn't match any of these.
日志文件显示是URLResolver错误。以下是日志文件
2018-06-11 17:42:19,210 django.template DEBUG Exception while resolving variable 'name' in template 'unknown'.
Traceback (most recent call last):
File "D:\Python_venvs\foo\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "D:\Python_venvs\foo\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "D:\Python_venvs\foo\lib\site-packages\django\urls\resolvers.py", line 523, in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried': [[<URLResolver <URLPattern list> (admin:admin) 'admin/'>]], 'path': 'foo/'}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python_venvs\foo\lib\site-packages\django\template\base.py", line 835, in _resolve_lookup
current = current[bit]
TypeError: 'URLResolver' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python_venvs\foo\lib\site-packages\django\template\base.py", line 843, in _resolve_lookup
current = getattr(current, bit)
AttributeError: 'URLResolver' object has no attribute 'name'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python_venvs\foo\lib\site-packages\django\template\base.py", line 849, in _resolve_lookup
current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'name'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python_venvs\foo\lib\site-packages\django\template\base.py", line 856, in _resolve_lookup
(bit, current)) # missing attribute
django.template.base.VariableDoesNotExist: Failed lookup for key [name] in <URLResolver <URLPattern list> (admin:admin) 'admin/'>
2018-06-11 17:42:19,213 django.request WARNING Not Found: /foo/
我几乎到处搜索,但似乎找不到遇到过类似问题的人。
技术设置:
- Windows 服务器 2012
- IIS 8
- Django 2.0.5
- Python 3.6.5
有什么想法吗?
编辑:urls.py
from django.contrib import admin
from django.urls import path,include
from polls import views
urlpatterns = [
path('admin/', admin.site.urls),
# path('polls/', include('polls.urls')),
]
我在这个 django 项目中创建了一个民意调查应用程序,但现在将其注释掉,因为它显示了与 it.So 相同的错误我想首先解决管理问题(我相信这也会解决民意调查应用问题)
我的 foo 项目结构:
foo
├── manage.py
├── web.config
├── foo
| ├── settings.py
| └── urls.py
| └── wsgi.py
| └──__init__.py
| └── static
| ├── admin
| | ├───css
| | └── fonts
| | └── img
| | └── js
| └── web.config
├── polls
| ├── admin.py
| └── urls.py
| └── apps.py
| └── models.py
| └── views.py
| └── tests.py
| └── migrations
我认为你没有添加 url 模式来将你路由到 127.0.0.1:8000/foo
在项目文件夹的urls.py中添加以下内容
url(r'foo/$', view_name, name='foo'),
这将添加到 /foo/
的路由(