Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django URL解析程序错误_Python_Django_Iis 8_Django 2.0 - Fatal编程技术网

Python Django URL解析程序错误

Python Django URL解析程序错误,python,django,iis-8,django-2.0,Python,Django,Iis 8,Django 2.0,我正在尝试使用IIS和wfastcgi在windows服务器上托管Django应用程序 在使用django-admin.py startproject foo创建了一个新的django项目之后,当我使用django服务器python manage.py runserver运行该项目时,管理页面会很好地打开 然而,当我试图通过127.0.0.1/foo访问它时,我得到了Django 404错误,它说: Django使用foo.URL中定义的URLconf尝试了以下URL 模式,按此顺序: 管理员/

我正在尝试使用IIS和wfastcgi在windows服务器上托管Django应用程序

在使用
django-admin.py startproject foo
创建了一个新的django项目之后,当我使用django服务器
python manage.py runserver
运行该项目时,管理页面会很好地打开

然而,当我试图通过127.0.0.1/foo访问它时,我得到了Django 404错误,它说:

Django使用foo.URL中定义的URLconf尝试了以下URL 模式,按此顺序:

管理员/

当前路径foo与这些路径都不匹配

日志文件显示这是一个URLSolver错误

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/
我在这个django项目中创建了一个polls应用程序,但由于它显示了相同的错误,所以暂时将其注释掉。因此我想首先解决管理问题(我相信这也会解决polls应用程序的问题)

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

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

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

这将添加到/foo/

(,)

的路由。您可以添加URL文件吗?请添加URL.py代码。您好,欢迎使用StackOverflow!请你再解释一下这个答案,以帮助人们理解它的作用?
url(r'foo/$', view_name, name='foo'),