Is there any way of making CSS changes be automatically updated on my template without having me refresh the page manually?
I saw this question has been asked few times but none of the answers there helped worked for me.
I added this code to get a new version of the CSSS file, not the old cached version when I reload the page. I think it might create some conflict. Here is the code:
<link rel="stylesheet" href='{% static 'signup.css' %}?{% now "U" %}'>
4
Answers
if you are using vanilla js (meaning no framework), there is a vscode extension called ‘live server’. It allows change detection and refreshes the page itself
To achieve live coding in a Django project without the need to manually refresh pages, you can use a development tool called "Django Auto-Reloader." This tool automatically reloads your Django server whenever it detects changes in your code, allowing you to see the updates without refreshing the page manually. Here’s how to set it up:
Install Django Auto-Reloader:
You can install Django Auto-Reloader using pip:
Add ‘autoreloader’ to your Django Apps:
Open your Django project’s
settings.py
file and add'autoreloader'
to theINSTALLED_APPS
list:Configure Auto-Reloader:
In your
settings.py
file, you can configure the Auto-Reloader to watch specific directories or file types for changes. By default, it monitors your project’s root directory and reloads when any.py
or.html
file changes. You can customize this behavior in yoursettings.py
:Run the Development Server:
Start your Django development server as usual:
The Auto-Reloader will automatically detect code changes and reload the server for you.
Start Coding:
Now, as you make changes to your Django project’s code (views, templates, models, etc.), the Auto-Reloader will refresh the server automatically, and you can see the updates in your web browser without manually refreshing the page.
Please note that while the Auto-Reloader is a great tool for speeding up your development workflow, it’s intended for use in development environments and should not be used in production. Be sure to turn it off or remove it from your production settings when deploying your Django project.
To achieve your desired result, you need to do two steps in VS code:
Use live-server
You can use the Live Server extension.
To save the steps of the code you write step by step, you need to follow these
steps :
2.1. Press Ctrl+Shift+P
2.2. Type "settings" and select "Open User Settings"
2.3. Type this code:
{"files.autoSave": "afterDelay"}
Finally, reload the window.
You have an auto update function in visual code!