help with the django tutorial part 1

101 views
Skip to first unread message

Russell Stanfield

unread,
Feb 2, 2016, 7:03:50 AM2/2/16
to Django users
Hi,

at this page:

https://docs.djangoproject.com/en/1.9/intro/tutorial01/

I have got this far in the tutorial:


In the polls/urls.py file include the following code:

polls/urls.py
from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
]

The next step is to point the root URLconf at the polls.urls module. In mysite/urls.py, add an import for django.conf.urls.include and insert an include() in the urlpatterns list, so you have:

mysite/urls.py
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', admin.site.urls),


You have now wired an index view into the URLconf. Lets verify it’s working, run the following command:

$ python manage.py runserver

When I try to start the server I get the following output:

root@russellberrypi:/home/mycode/mysite# python manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x20aaaf0>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run
    self.check(display_num_errors=True)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 426, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 75, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 10, in check_url_config
    return check_resolver(resolver)
  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 19, in check_resolver
    for pattern in resolver.url_patterns:
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 417, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 410, 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/mycode/mysite/mysite/urls.py", line 20, in <module>
    url(r'^polls/', include('polls.urls')),
  File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 52, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/mycode/mysite/polls/urls.py", line 8
    url(r'^$, views.index, name='index'),
                                                                 ^
SyntaxError: invalid syntax



I think all the files  I have created/edited look good, but can put them up here if required....



Bipul Raj

unread,
Feb 2, 2016, 7:38:19 AM2/2/16
to django...@googlegroups.com
  >> url(r'^$, views.index, name='index'),

Are you sure if you have closing single quote with r'^$ ? I do not see it in error.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/643917c9-17f7-4e0c-aed0-df8ab1e9f831%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

林攀

unread,
Feb 2, 2016, 9:16:45 AM2/2/16
to django...@googlegroups.com

Sergiy Khohlov

unread,
Feb 2, 2016, 9:46:03 AM2/2/16
to django-users
 SHould be

 url(r'^$', views.index , name='index')


 you have missed  '

Many thanks,

Serge


+380 636150445
skype: skhohlov

Russell Stanfield

unread,
Feb 2, 2016, 9:47:27 AM2/2/16
to Django users, 18610...@163.com
yes, that was it, thanks it's running now....
Reply all
Reply to author
Forward
0 new messages