On 25 Aug 2014 22:12, "Jagger" <zun...@gmail.com> wrote: > > It works. Thanks. I removed the hardcoded URLs from the templates and I refer to index in this way: > > <a class="mainmenuitemlink" href="{% url 'index' %}">NEWS</a> > > You asked why I gave the two patterns the same name. > The website default page is 'index'. It contains the news. The News menu also points to index. > Pattern A maps index to root: > > url(r'^$', views.index, name='index') > Pattern B is used in the menu: > > url(r'^index/$', views.index, name='index') > > Perhaps, I could use pattern A in the menu, but it wouldn't be elegant, would it? > > Or is it too complicated... ? > > BTW, I could leave out 'name' parameter from pattern A, because I only use pattern B in templates: > url(r'^$', views.index) > Do you agree?
You need to give every pattern a unique name. The name argument is optional though so you can leave it out until you need. > > > 2014. augusztus 25., hétfő 10:12:14 UTC+2 időpontban Tundebabzy a következőt írta: >> >> Ok. I'm replying inline: >> >> On 24 Aug 2014 18:43, "Jagger" <zun...@gmail.com> wrote: >> > >> > The link is in the base.html of spweb app: >> > >> > <a class="mainmenuitemlink" href="index">NEWS</a> >> > >> This link is relative so the browser will append the href attribute to the present URL. You should change it to: >> <a class="mainmenuitemlink" href="/index/">NEWS</a> >> >> >> >> >> On 24 Aug 2014 12:30, "Jagger" <zun...@gmail.com> wrote: >> >>> >> >>> Hi Everyone! >> >>> >> >>> >> >>> >> >>> I use Python 2.7 and Django 1.6 on Xubuntu 14.04. >> >>> >> >>> >> >>> I'm a beginner. My problem is: >> >>> >> >>> >> >>> The root URLConf: >> >>> >> >>> from django.conf.urls import patterns, include, url >> >>> >> >>> >> >>> from django.contrib import admin >> >>> >> >>> >> >>> admin.autodiscover() >> >>> >> >>> >> >>> urlpatterns = patterns('', >> >>> >> >>> url(r'^admin/', include(admin.site.urls)), >> >>> >> >>> url(r'^', include('spweb.urls')), >> >>> >> >>> ) >> >>> >> >>> >> >>> >> >>> The URLConf of spweb app: >> >>> >> >>> >> >>> from django.conf.urls import patterns, url >> >>> >> >>> >> >>> from spweb import views >> >>> >> >>> >> >>> urlpatterns = patterns('', >> >>> >> >>> url(r'^$', views.index, name='index'), >> >>> >> >>> url(r'^index/$', views.index, name='index'), >> >> Why did you give the 2 patterns the same name ('index')? Because Django can automatically fill in the URL linked to a name by using the url template tag: >> <a class="mainmenuitemlink" href="{% url 'index' %}">NEWS</a> >> >> >>> >> >>> url(r'^contact/$', views.contact, name='contact'), >> >>> >> >>> ) >> >>> >> >>> >> >>> In a browser the first click on a link link points to http://127.0.0.1:8000/index (OK, that's correct. This is what I expect to happen.) >> >>> >> >>> But the second click on the same link points to http://127.0.0.1:8000/index/index (That's wrong. Why did the url change???) >> >> BTW note that http://example.com is different fron http://example.com/. >> >>> >> >>> >> >>> >> >>> Thans for your answers! > > -- > 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/a4e03a28-7a97-4907-98f6-a8d8e056bb6f%40googlegroups.com . > > For more options, visit https://groups.google.com/d/optout. -- 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/CA%2BWjgXMH5ygd-AEqcZcLJoM3LXdjTVK8d2f7V8vncPUQigPNsw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.