【发布时间】:2018-11-21 07:30:12
【问题描述】:
我正在尝试使用 IIS 使用 wfastcgi 在 Windows 服务器上托管 Django 应用程序。
使用django-admin.py startproject foo 创建一个新的django 项目后,当我使用django 服务器python manage.py runserver 运行它时,管理页面可以正常打开。
但是,当我尝试通过 127.0.0.1/foo 访问它时,我收到 Django 404 错误消息:
使用 foo.urls 中定义的 URLconf,Django 尝试了这些 URL 模式,按以下顺序:
管理员/
当前路径 foo 与其中任何一个都不匹配。
日志文件显示是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 项目中创建了一个民意调查应用程序,但现在将其注释掉,因为它显示了相同的错误。所以我想首先解决管理问题(我相信这也可以解决民意调查应用程序问题)
我的 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
【问题讨论】:
-
你能添加你的urls文件吗?
-
请添加您的 urls.py 代码。
标签: python django iis-8 django-2.0