Home Ask Login Register

Developers Planet

Your answer is one click away!

Hannah Wight February 2016

How to link html files together using Django 1.9?

I am currently programming in the atom code editor and python 3.4.0 as well as Django 1.9. I am new to django coding.

This is the tree view for where all my html file and css files are.

I have managed to link the html files and the css files, but I don't know how to link the html files together.

I have tried the <a href=" "> code because normally that works (I have previous knowledge in HTML) however, everytime I click on the link, it says webpage not found.

I am trying to link base.html file to the generalq.html file.

Does anyone know any tips?


pp_ February 2016

You have to put an URL in the href of your <a> element that is handled by your urls.py and views.py files:

In blog/templates/blog/base.html:

<a href="/blog/general/">My link</a>

In compproject/urls.py:

from django.conf.urls import include, url

urlpatterns = [
    url(r'^blog/', include('blog.urls')),

In blog/urls.py:

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

urlpatterns = [
    url(r'^general/$', views.general, name='general'),

In blog/views.py:

from django.shortcuts import render

def general(request):
    return render(request, 'blog/generalq.html', {})

Post Status

Asked in February 2016
Viewed 2,215 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life