Django URLResolver错误

时间:2018-06-12 01:18:14

标签: python django iis-8 django-2.0

我正在尝试使用wfastcgi在IIS服务器上托管一个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 Server 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项目中创建了一个民意调查应用程序,但现在评论它,因为它显示了相同的错误。所以我想首先解决管理问题(我相信它也会修复民意调查应用程序问题)< / p>

我的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

2 个答案:

答案 0 :(得分:0)

我认为你没有添加网址格式来引导你到127.0.0.1:8000/foo

在项目文件夹的urls.py中添加以下内容

url(r'foo/$', view_name, name='foo'),

这将添加到/ foo /

的路由

答案 1 :(得分:-1)

(无:无)''>,)