user2320239
user2320239

Reputation: 1038

Django link does not display new template

I'm just starting with django/web development and I've run into a problem. In my templates folder I have base.html, home.html and licences.html templates. In the home.html I have a link <li><a href="{% url 'licences' %}">Licences</a></li> and in my views.py I have the method licences(request):

def licences(request):
    return render(request, "licences.html", {})

However if I then run the server and click the link, I get the a blank page with just the base.html elements being displayed.

How do I fix this to display the new page?

EDIT:

urls.py

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', 'searchFilm.views.home', name='home'),
    url(r'^results/$', 'searchFilm.views.results', name='results'),
    url(r'^licences/$', 'searchFilm.views.licences', name='licences')

]

licences.html

<html>

    <head>
        <!-- <title>{% block title %}HomePage{% endblock %}</title> -->
    </head>

    <body>

        <p>This page contians informations on the licences</p>

    </body>

</html>

Upvotes: 0

Views: 144

Answers (3)

user2320239
user2320239

Reputation: 1038

I worked out what the problem was, turns out you can't comment out Django tags using HTML comments, so even though {% extends "base.html" %} was inside a comment, the page was still extending base.html. If I completely removed the extends tag, or changed licences.html to comply with base.html it worked as intended.

Upvotes: 0

Aditya Singh
Aditya Singh

Reputation: 970

Need to see the structure of base.html but i think u r not Including base.html

Upvotes: 0

Pela647
Pela647

Reputation: 31

Have you populated your licenses table( do you have data in your licenses table)? The main reason you get a blank table is because you are missing one line of code between your def statement and return statement, you need a query statement like:

licences=nameOfYourLicencesTable.objects.get(pk=id)

Then you can use at your template:

<li><a href="{{ licenses.licensesColumnName}}">Licences</a></li>

Upvotes: 0

Related Questions