CSS not working in some pages on Django

I am a beginner in Python and Django and I have been struggling with the following problem:

On localhost:8000/ webiste is beautiful and working fine but on localhost:8000/invoice/ SOME references are not working. CSS for example does not work but images and JavaScript do.

I am using relative links to point out where my path is.

    <script src="{% static "js/jquery.min.js" %}"></script>
    <script src="{% static "js/skel.min.js" %}"></script>
    <script src="{% static "js/skel-layers.min.js" %}"></script>
    <script src="{% static "js/init.js" %}"></script>

    <noscript>
        <link rel="stylesheet" href="{% static "css/skel.css" %}"/>
        <link rel="stylesheet" href="{% static "css/style.css" %}"/>
        <link rel="stylesheet" href="{% static "css/style-xlarge.css" %}"/>
    </noscript>

    <img src="{% static "images/pic07.jpg" %}" alt="" />

Settings.py

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static/"),
)

View.py

def home(request):
  return render(request, 'principal.html',)

def invoice(request):
  return render(request, 'invoice.html',)

When I check the page code with the browser I see the links are being referred as http://localhost:8000/invoice/static/css/somecss.css.

invoice.html is inside /project/folder/templates/ and my .css is inside /project/static/css/. invoice.html is inside the same folder my index.html (principal.html) page, which is working is.

Also, all links inside website/invoice/ page become website/invoice/link instead of website/link

Answers


Problem has been resolved removing tag. Also for 404 errors on console due to js files referencing other css files, I added a variable to my template to include the url:

<script>
  var url = "{% static 'css/' %}";
</script>

And inside .js I used url.concat('style.css')


Need Your Help

How to use maven-m2e-codestyle connector?

eclipse maven m2e

According to https://issues.sonatype.org/browse/OSSRH-3293 "Maven m2e Code-Style and Save-Actions connector"

Update cached data

asp.net sql-server architecture

U are caching a list of items, then Add or update or delete method called.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.