In the polls/urls.py
file include the following code:
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:
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 anindex
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....
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHHn46TrWi6v4o2-8LwQj6PgwMwVpftAzx3QkoLZoxGhtcdTAw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/109496ce.3553.152a2476efa.Coremail.18610710105%40163.com.