UPLOAD STATIC FILES

29 views
Skip to first unread message

Obiorah Callistus

unread,
May 29, 2023, 11:31:33 AM5/29/23
to Django users
please how can i display .css and .js files in my template

Music Fm

unread,
May 29, 2023, 11:51:52 AM5/29/23
to django...@googlegroups.com
Load static

Open a folder call it static then open another file within the static forder. 

Now type {load static/custom.css }on the html file it will see the static that has the css and javascript file

On Mon, May 29, 2023, 4:31 PM Obiorah Callistus <ockp...@gmail.com> wrote:
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 django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5a2ceeec-20f1-46aa-98b9-717c9965b82dn%40googlegroups.com.

Kasper Laudrup

unread,
May 29, 2023, 12:42:28 PM5/29/23
to django...@googlegroups.com
On 29/05/2023 04.24, Obiorah Callistus wrote:
> please how can i display .css and .js files in my template
>

Have you considered reading the documentation?

Kind regards,
Kasper Laudrup
OpenPGP_0xE5D9CAC64AAA55EB.asc
OpenPGP_signature

SHUBHAM KUMAR

unread,
May 30, 2023, 12:05:59 AM5/30/23
to django...@googlegroups.com
you should add STATIC_DIR =[

'BASE'/ 'static'

]
to your project settings 

sum abiut

unread,
May 30, 2023, 12:52:18 AM5/30/23
to django...@googlegroups.com
in your setting make sure you have
STATIC_URL = '/static/'

then in your template
you load static at the top of your htmi file like this.
{% load static %}
to load any static files like css. do something like this
{% static './cssfile.css'%}

Then run the command. python manage.py collectstatic


Music Fm

unread,
May 30, 2023, 1:16:10 AM5/30/23
to django...@googlegroups.com
Message has been deleted

DieHardMan 300

unread,
May 30, 2023, 3:23:33 AM5/30/23
to Django users
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>
------------------------------------------------------------------------


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

Colin Ado

unread,
May 30, 2023, 10:55:23 AM5/30/23
to django...@googlegroups.com
1. Create a folder called static, and inside the static folder create another folder
2. Go to settings.py AND add this:
STATIC_URL = 'static/'

STATICFILES_DIRS = [
    BASE_DIR / 'static'
]
3. Go to your .html file and like the .css file using:
<link rel="stylesheet" href="{% static 'folder_inside_static/css_file_inside_folder_inside_static.css' %}">

On Mon, 29 May 2023 at 18:31, Obiorah Callistus <ockp...@gmail.com> wrote:
please how can i display .css and .js files in my template

--
Reply all
Reply to author
Forward
0 new messages