Question

I'm writing a django website and I want to use 'Semantic UI' for its front end. but when I add a Semantic UI Button to my first page in django, it only shows plain text!

the file tree of my project is like this :

Matab->
----Matab->
--------Templates->
--------------base.html
--------------login.html
---------settings.py
-----media->
--------css->
------------semantic.css

settigs.py :

MEDIA_ROOT = os.path.join(os.path.dirname(__file__),'../media/').replace('\\','/')
MEDIA_URL = '/media/'

base.html :

<html>
        <head>
            <link rel="stylesheet" href="{{ MEDIA_URL }}css/semantic.css"/>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <meta name="author" content="Navid" />
        </head>
        <body>
            <div id="mainContent">
            {% block content %}{% endblock %}
            </div>
        </body>
    </html>

login.html:

{% extends 'base.html' %}
{% block content %}
    <div class="ui button">hello</div>
{% endblock %}
Was it helpful?

Solution 2

The problem was in urls.py, I should insert this line :

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

OTHER TIPS

Edit: Please use STATIC_ROOT and STATIC_URL instead of MEDIA_ROOT and MEDIA_URL. And follow the doc to setup the static file directories.

Your MEDIA_ROOT path is wrong. Update it to this -

MEDIA_ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'media')

Here os.path.dirname(__file__) evaluates to second Matab directory. Using os.path.dirname() again, takes it to First Matab directory. Then you just join it with media. Python automatically adds the slashes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top