Today, I dedicated all my time to setting up a small Django app on cPanel. After configuring the Python virtual environment, adding Django files, and installing dependencies...
I encountered an issue with loading static CSS and JavaScript files properly.
The cPanel host placed passenger_wsgi.py inside my Django app directory and configured .htaccess to point to the wsgi file, which is handling the requests.
The static files are in the same location as during development and are defined in settings.py
STATIC_URL = "/static/"
STATIC_ROOT = "/path/to/public_html/static/"
STATICFILES_DIRS = [( "static", "/path/to/myapp/static/" ),]
In templates/base/navigation.html (I also attempted {% load static %})
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% endblock %} | SG</title>
<script src="{% static 'js/jquery.min.js' %}" type="text/javascript"></script>
<script src="{% static 'js/bootstrap.min.js' %}" type="text/javascript"></script>
<script src="{% static 'js/custom.js' %}" type="text/javascript"></script>
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet" type="text/css">
...
After running python manage.py collectstatic, I can see all my static files. However, only the landing page is able to load these static files.
All other pages (admin, blog, etc.) seem to append the app/directory name to the link/script tag, resulting in errors.
Additionally, in my templates/blog/blogs.html
{% extends 'base/navigation.html' %}
{% block content %}
<div class="container">
{% for blog in blogs %}
...
Has anyone faced this issue before? What could be causing this request problem?
I've been troubleshooting this throughout the day, so if there are any details that I missed, please feel free to let me know. I'm going to take a break now.