settings.py
    - add following line if not exist
----------------------------------------------------------------------
STATIC_URL = 'static/'
------------------------------------------------------------------------
    in your static folder ---> project_name/app_name/static/app_name/
* I recommend create another folder in your static folder with your app 
name to avoid duplicate static file name with other apps
* Also I recommend create "new folder" name "css" and "js"
--> project_name/app_name/static/app_name/css
--> project_name/app_name/static/app_name/js

now on top of your "template" html file add following line:
    * note that you must add this line for every template you using static 
or "extends" from template that use static
------------------------------------------------------------------------
{% load static %}
------------------------------------------------------------------------

    how to import css
------------------------------------------------------------------------
<link rel="stylesheet" href="{% static 'app_name/css/hello.css' %}">
or
<span style="{% static 'app_name/css/hello.css' %}">hello, world</span>
------------------------------------------------------------------------
    
    how to import javascript
------------------------------------------------------------------------
<script src="{% static 'app_name/js/hello.js' %}"></script>
------------------------------------------------------------------------

in django tutorial --> 
https://docs.djangoproject.com/en/4.2/intro/tutorial06/
and documentation for this --> 
https://docs.djangoproject.com/en/4.2/howto/static-files/

ในวันที่ วันจันทร์ที่ 29 พฤษภาคม ค.ศ. 2023 เวลา 22 นาฬิกา 31 นาที 33 วินาที 
UTC+7 Obiorah Callistus เขียนว่า:

> please how can i display .css and .js files in my template

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b8de72ab-fc82-4a44-9354-84d3f3890e73n%40googlegroups.com.

Reply via email to