Search code examples
pythondjangoiis-8django-2.0

Django URLResolver error


I am trying to host a Django app on windows server using IIS using wfastcgi.

After creating a new django project using django-admin.py startproject foo,the admin page opens up fine when I run it with the django server python manage.py runserver.

However when I try to access it through 127.0.0.1/foo I get the Django 404 error saying :

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.

The log file shows that it is a URLResolver error .Following is the log file

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/

I have searched almost everywhere but I cant seem to find anyone who has had a similar issue.

Technical setup:

  • Windows Server 2012
  • IIS 8
  • Django 2.0.5
  • Python 3.6.5

Any ideas?

Edit: 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')),

]

I created a polls app in this django project but commented it out for now since it was showing the same error for it.So I thought to first tackle the admin issue (which I believe would also fix the polls app issue)

My foo project structure:

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

Solution

  • I think you have not added a url pattern to route you to 127.0.0.1:8000/foo

    In the urls.py in project folder add the following

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

    This will add a route to /foo/