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/js/hello.js' %}"> or <span style="{% static '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 django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/16f24801-c43d-4381-9d96-3ee1885a07b5n%40googlegroups.com.