Reputation: 107
I'm doing a Python-Django web app.And I got an error on urls.py when
I'm trying to run the project using python manage.py runserver
The below given is my error.
Not Found: /hello
[09/Nov/2016 16:22:34] "GET /hello HTTP/1.1" 404 1920
Performing system checks...
Unhandled exception in thread started by <function wrapper at 0xb68f7924>
Traceback (most recent call last):
File "/home/nishanth/nenv/local/lib/python2.7/site-packages/Django-1.10.3-py2.7.egg/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/nishanth/nenv/local/lib/python2.7/site-packages/Django-1.10.3-py2.7.egg/django/core/management/commands/runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "/home/nishanth/nenv/local/lib/python2.7/site-packages/Django-1.10.3-py2.7.egg/django/core/management/base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "/home/nishanth/nenv/local/lib/python2.7/site-packages/Django-1.10.3-py2.7.egg/django/core/management/base.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "/home/nishanth/nenv/local/lib/python2.7/site-packages/Django-1.10.3-py2.7.egg/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/nishanth/nenv/local/lib/python2.7/site-packages/Django-1.10.3-py2.7.egg/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/home/nishanth/nenv/local/lib/python2.7/site-packages/Django-1.10.3-py2.7.egg/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/home/nishanth/nenv/local/lib/python2.7/site-packages/Django-1.10.3-py2.7.egg/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/nishanth/nenv/local/lib/python2.7/site-packages/Django-1.10.3-py2.7.egg/django/urls/resolvers.py", line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/nishanth/nenv/local/lib/python2.7/site-packages/Django-1.10.3-py2.7.egg/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/nishanth/nenv/local/lib/python2.7/site-packages/Django-1.10.3-py2.7.egg/django/urls/resolvers.py", line 306, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/nishanth/Documents/register/register/urls.py", line 16, in <module>
from django.conf.urls import patterns, include, url
ImportError: cannot import name patterns
Performing system checks...
This is my urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns['',
url(r'^admin/', admin.site.urls),
url(r'^hello/$', 'blog.views.hello'),
url(r'^hello_template/$' , 'blog.views.hello_template'),
]
How can I solve this problem
Upvotes: 0
Views: 1903
Reputation: 78546
Newer versions of Django (like 1.10 which you're on) do not use patterns
. Just put the urls in a list. You'll also need to import the view functions that will handle each url and supply those instead of the strings as parameters:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^hello/$', views.hello),
url(r'^hello_template/$' , views.hello_template),
]
See the https://docs.djangoproject.com/en/1.10/topics/http/urls/#example
Upvotes: 5