Url problem

28 views
Skip to first unread message

VilleP

unread,
Jul 12, 2016, 7:28:30 AM7/12/16
to Django users
Hi guys!

I've got a little problem with my url "generating". Everytime I try to run my testserver and move through pages, that I've linked there it goes like this:

http://testserver.local/home #(this is totally fine)
(click on another page)
(click on another page besides home)
(if I click again to previous by clicking menu button it goes like this)

page1, etc. are examples here which helps me to present the problem.

Any help for this one? I'll paste my urls.py and views.py below:


from django.conf.urls import url
from sivusto import views

urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^tekninen.html/$', views.tekninen, name='tekninen'), #(this would be page1)
url(r'^johdon_tyokalut.html/$', views.johdon_tyokalut, name='johdon_tyokalut'), #(this would be page2)
]


from django.shortcuts import render

def index(request):
return render(request, 'sivusto/index.html',) #(homepage)
def tekninen(request):
return render(request, 'sivusto/tekninen.html',) #(page1)
def johdon_tyokalut(request):
return render(request, 'sivusto/johdon_tyokalut.html',) #(page2)


This is the main main urls.py, if it helps:


from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
url(r'^sivusto/', include('sivusto.urls', namespace="sivusto")),
]


Thank you very much in advance, I know this sounds like a noob problem but that's pretty much what I'm dealing with here :D

James Schneider

unread,
Jul 12, 2016, 9:19:12 AM7/12/16
to django...@googlegroups.com


On Jul 12, 2016 4:27 AM, "VilleP" <pasone...@gmail.com> wrote:
>
> Hi guys!
>
> I've got a little problem with my url "generating". Everytime I try to run my testserver and move through pages, that I've linked there it goes like this:
>
> http://testserver.local/home #(this is totally fine)
> (click on another page)
> http://testserver.local/home/page1
> (click on another page besides home)
> http://testserver.local/home/page1/page2
> (if I click again to previous by clicking menu button it goes like this)
> http://testserver.local/home/page1/page2/page1
>

This is happening because your site is generating links using a short relative path (href='page1'). Are you generating URL paths using the Django methods such as reverse() and {% url %}?

> page1, etc. are examples here which helps me to present the problem.
>
> Any help for this one? I'll paste my urls.py and views.py below:
>
>
> from django.conf.urls import url
> from sivusto import views
>
> urlpatterns = [
> url(r'^$', views.index, name='index'),
> url(r'^tekninen.html/$', views.tekninen, name='tekninen'), #(this would be page1)
> url(r'^johdon_tyokalut.html/$', views.johdon_tyokalut, name='johdon_tyokalut'), #(this would be page2)
> ]

Can you provide an example of a problematic {% url %} tag from your template, and the generated HTML on the browser for that same anchor?

Based on the urls.py files you posted, the behavior you describe shouldn't be possible. Is this behavior seen using the dev server, or using a production server like Apache?

-James

VilleP

unread,
Jul 18, 2016, 6:37:29 AM7/18/16
to Django users
Thanks James for your quick answer, the problem occurred on dev server as I haven't deployed the site yet. But I figured out how to fix this, which was suitable for everybody. Just used multiple apps, instead of one.

Thanks a lot :)

-Ville
Reply all
Reply to author
Forward
0 new messages