Milan Rasovic
Milan Rasovic

Reputation: 31

Django views rendering just one page and wont render the rest

So im using django 1.8 on macosx and i have problem while configuring html, namely when i try to load another page except one that is set at default one(index is the default one), it just refreshes the default one i have set in urls.py and i cant access any other page except that one but in the url bar i can see that im accesing the proper html file because it says so but the page is not changing....heres my code:

app/urls.py-----------

urlpatterns = [
    url(r'^contact/', views.contact, name='contact'),
    url(r'^projects/', views.projects, name='projects'),
    url(r'^services/', views.services, name='services'),
    url(r'^', views.index, name='index'),
    url(r'^about/', views.about, name='about'),

these are all the pages im trying to install main urls.py------------- from app import views

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

]

and this is my views.py-----------

def contact(request):
    return render(request, 'app/template/contact.html',{})

def about(request):
    return render(request, 'app/template/about.html',{})

def projects(request):
    return render(request, 'app/template/projects.html',{})

def services(request):
    return render(request, 'app/template/services.html',{})

def index(request):
    return render(request, "app/template/index.html",{})

Upvotes: 1

Views: 893

Answers (1)

Nico Zimmer
Nico Zimmer

Reputation: 318

https://docs.djangoproject.com/en/1.8/intro/tutorial03/

you need $ to end the string. In your case he link all thats starts with all.

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

you views.py:

def contact(request):
    return render(request, 'app/contact.html',{})

def about(request):
    return render(request, 'app/about.html',{})

def projects(request):
    return render(request, 'app/projects.html',{})

def services(request):
    return render(request, 'app/services.html',{})

def index(request):
    return render(request, "app/index.html",{})

Upvotes: 4

Related Questions