On Friday, March 14, 2014 8:14:57 PM UTC-4:30, David wrote: > > I am wodering whether my implementation is incorrect or whether there is > a typo in the textbook. My question is how I can make sense of these > instructions: "The regular expression to match about/ is r'^about/'". > > I was following the "Tango with Django" book. > > In the exercises of chapter 3 I am asked to > > """ > Now map the view ['about', which we just created] to /rango/about/. For > this step, you’ll only need to edit the urls.py of the rango application. > """ > > Later, the author gives some hints, specifically: > > > """ > The regular expression to match about/ is r'^about/' > """ > > Now, there was no way to do this. I finally managed to get > > http://127.0.0.1:8000/rango/ and > http://127.0.0.1:8000/rango/about/ > > running satisfactorily (my code is below), but I was not even sure this > was intended. The author possibly wanted to create > > http://127.0.0.1:8000/about/ instead of > http://127.0.0.1:8000/rango/about/ > > Thanks for clarifying this issue for me! > > Cheers, > > David > > > > > Here is my project/urls.py > > from django.conf.urls import patterns, include, url > > from django.contrib import admin > admin.autodiscover() > > urlpatterns = patterns('', > # Examples: > # url(r'^$', 'justnow.views.home', name='home'), > # url(r'^blog/', include('blog.urls')), > > # url(r'^admin/', include(admin.site.urls)), > url(r'^rango/', include('rango.urls')), # ADD THIS NEW TUPLE! > url(r'^about/', include('rango.urls')), # ADD THIS NEW TUPLE! > ) > > > > The app urls.py: > > from django.conf.urls import patterns, include, url > from rango import views > > urlpatterns = patterns('', > url(r'^$', views.index, name='Rangos index'), > url(r'about', views.about, name='About page'), > ) > > The app views.py: > > from django.http import HttpResponse > > def index(request): > return HttpResponse("Rango says hello. <a > href='/rango/about/'>About</a>") > > def about(request): > return HttpResponse("Here is the about page. <a > href='/rango/'>Index</a>") > > > > > > > > david@ubuntu:~/[...]/django_project$ tree > . > ├── manage.py > ├── notes.txt > ├── rango > │ ├── admin.py > │ ├── admin.pyc > │ ├── __init__.py > │ ├── __init__.pyc > │ ├── models.py > │ ├── models.pyc > │ ├── tests.py > │ ├── urls.py > │ ├── urls.pyc > │ ├── views.py > │ └── views.pyc > └── tango_with_django_project > ├── __init__.py > ├── __init__.pyc > ├── settings.py > ├── settings.pyc > ├── urls.py > ├── urls.pyc > ├── wsgi.py > └── wsgi.pyc > Hello,
To point the about view to http://127.0.0.1:8000/about/, in you project/urls.py, you should change: url(r'^about/', include('rango.urls')), # ADD THIS NEW TUPLE! to url(r'^about/', rango.views.about, name='About page'), (of course, you have to import rango.views) With your current configuration, these two links: http://127.0.0.1:8000/rango/ and http://127.0.0.1:8000/rango/about/ points to the same as: http://127.0.0.1:8000/about/ <http://127.0.0.1:8000/rango/> and http://127.0.0.1:8000/about/about/ <http://127.0.0.1:8000/rango/about/> Because you included the same urls for 'rango/' and 'about/' Yours, Camilo -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/809b5684-ce25-469a-bb4b-13571bcc01f9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.