0

I have a problem with including css and js files. My index page works fine, but when I try to put the same code to the detail page it doesn't work, not even html wich I wrote on detail.html, just the include files from master.html work. What can be the problem?

master.html

<!DOCTYPE html>
<html>
<head>
    <title>{% block title %}{% endblock %}</title>
    <link href="static/font.min.css" rel="stylesheet">
    <link href="static/bootstrap.min.css" rel="stylesheet">
    <link href="static/font-awesome.min.css "rel="stylesheet">
    <link href="static/main.css" rel="stylesheet">
</head>     
<body data-spy="scroll" data-target="#navbar" data-offset="0">
        {% include "header.html" %}
        {% include "carausel.html" %}
        {% block h1 %}{% endblock %}
        {% include "footer.html" %}
    <script src="static/jquery.js"></script>
    <script src="static/bootstrap.min.js"></script>
    <script src="static/jquery.isotope.min.js"></script>
    <script src="static/jquery.prettyPhoto.js"></script>
    <script src="static/main.js"></script>
</body>

detail.html

{% extends "master.html"  %}
{% block h1 %}
<div class="box first">
<div class="row">
    <div class="container">
        {% for question  in latest_question_list %}
            <div class="col-xs-12 col-sm-4 col-md-3">
                <div class="center">
                    <a href="{{ question.slug }}" i class="icon-credit-card icon-md icon-color1"></a>
                    <h4>{{ question.naslov }} </h4>
                    <p>{{ question.opis }}</p>
                </div>
            </div>
        {% endfor %}
    </div>
</div>

{% endblock %}
{% block title  %} Detail {% endblock %}

views.py

from django.shortcuts import render

from .models import Question


def index(request):
    latest_question_list = Question.objects.all()
    context = {'latest_question_list': latest_question_list}
    return render(request, 'papers/index.html', context)

def detail(request, slug):
     question = Question.objects.get(slug=slug)
     return render(request, 'papers/detail.html', {'question': question})

urls.py

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


urlpatterns = [
   url(r'^$', 'papers.views.index', name='index'),
   url(r'^admin/', include(admin.site.urls)),
   url(r'^(?P<slug>[\w_-]+)/$', 'papers.views.detail', name='detail'),
]    

urlpatterns += staticfiles_urlpatterns()
3
  • (I'm assuming django) what's in your urls.py concerning static? Commented May 14, 2015 at 17:22
  • what does your index.html look like? it seems to be an issue of you not inheriting from the masterpage correctly. Commented May 14, 2015 at 17:25
  • index.html looks the same as detail.html and they extend master.html. Put the same code just to see if it will work Commented May 14, 2015 at 17:32

1 Answer 1

2

Use absolute paths for all your static links.

 <link href="/static/....
 <script src="/static/...
Sign up to request clarification or add additional context in comments.

5 Comments

you should probably use the {% static %} template tag
The js and css are included, that works. But the question fields from the DB, do not apper.
Everything under {% block h1 %}{% endblock %} doesn't appear
That appears to be a different question. But you don't have anything called latest_question_list coming from your detail view, so it's not surprising that nothing shows.
How should I write def detail in views? thanks, you are very helpfull.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.