skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. 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:

    1. Install Django Auto-Reloader:

      You can install Django Auto-Reloader using pip:

      pip install django-autoreloader
      
    2. Add ‘autoreloader’ to your Django Apps:

      Open your Django project’s settings.py file and add 'autoreloader' to the INSTALLED_APPS list:

      INSTALLED_APPS = [
          # ...
          'autoreloader',
          # ...
      ]
      
    3. 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 your settings.py:

      # Auto-Reloader Configuration
      AUTO_RELOADER_WATCH_DIRS = [
          # Add directories to watch for changes
      ]
      
      AUTO_RELOADER_IGNORE_PATTERNS = [
          # Add patterns to ignore specific files or directories
      ]
      
    4. Run the Development Server:

      Start your Django development server as usual:

      python manage.py runserver
      

      The Auto-Reloader will automatically detect code changes and reload the server for you.

    5. 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.

    Login or Signup to reply.
  3. To achieve your desired result, you need to do two steps in VS code:

    1. Use live-server
      You can use the Live Server extension.

    2. 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.

    Login or Signup to reply.
  4. You have an auto update function in visual code!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search