Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8686947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:59:37+00:00 2026-06-12T22:59:37+00:00

I had to come up with quite a complicated setup to enable database based

  • 0

I had to come up with quite a complicated setup to enable database based styling options for users. Users enter styles (like background color, font face, etc…) in the django admin backend.

I am creating a dynamic LESS file by rendering a template view as plain text view like so:

views.py:

class PlainTextView(TemplateView):
    """
    Write customized settings into a special less file to overwrite the standard styling
    """
    template_name = 'custom_stylesheet.txt'

    def get_context_data(self, **kwargs):
        context = super(PlainTextView, self).get_context_data(**kwargs)
        try:
            #get the newest PlatformCustomizations dataset which is also activated
            platform_customizations = PlatformCustomizations.objects.filter(apply_customizations=True).order_by('-updated_at')[0]
        except IndexError:
            platform_customizations = ''

        context.update({
            'platform_customizations': platform_customizations,
        })
        return context


    def render_to_response(self, context):
        return super(PlainTextView, self).render_to_response(context, content_type='plain/text')

The template custom_stylesheet.txt looks kind of like this. It takes the database styling entries the users entered in the admin backend:

@CIBaseColor: {{ dynamic_styles.ci_base_color }};
@CIBaseFont: {{ dynamic_styles.ci_base_font }};
...etc...

Now I include this dynamic less files in my main.less file with other normal static LESS files. Like so:

main.less:

@import "bootstrap_variables.less";

//this is the dynamicly created custom stylesheet out of the dynamic_styles app
@import url(http://127.0.0.1:8000/dynamic_styles/custom_stylesheet.less);

//Other styles
@import "my_styles.less";

This setup works fine. The dynamic variables out of my database get rendered into the template and LESS compiles all my less files together.

I have a problem when pushing the code to my production setup where I compile the LESS server side and compress it with django-compressor.

I get the following error:

FilterError: [31mFileError: 'http://127.0.0.1:8000/dynamic_styles/custom_stylesheet.less' wasn't found.
[39m[31m in [39m/home/application/***/media/static-collected/styles/less/main.less[90m:13:0[39m
[90m12 //this is the dynamicly created custom stylesheet out of the dynamic_styles app[39m
13 [7m[31m[1m@[22mimport url(http://127.0.0.1:8000/dynamic_styles/custom_stylesheet.less);[39m[27m
[90m14 [39m[0m

Has anybody ever experienced problems with django compressor like that? Does it have problems with dynamically created files like this? Could the absolute url be a problem?

Could you think of another solution get dynamically generated less files working with django compressor?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:59:38+00:00Added an answer on June 12, 2026 at 10:59 pm

    I guess Django-Compressor can’t read dynamically created less files which are only available “on-the-fly” if you hit the url. At least I did not get it working. Also the file needs to be on the COMPRESS_ROOT.

    Now I write the less file to disk physically every time the model gets saved. Here’s the code. It still needs some improvement like try except, etc. But it works:

     def save(self, *args, **kwargs):
    
        #todo add try except
        less_file = open(os.path.join(settings.PROJECT_ROOT, 'media', 'static', "styles", "less", "custom_stylesheet.less"), "w")
        less_file.write(render_to_string('template/custom_stylesheet.txt', {'platform_customizations': self}))
        less_file.close()
    
        super(PlatformCustomizations, self).save(*args, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what are some good tag Cloud logic that you had come up with? like
I've come across quite a bit of theory regarding Bloomier filters but have had
Had a good read through similar topics but I can't quite a) find one
I've come across several examples of SOAP-based web services where automated tooling fails to
I am quite new to C# (I had an RS-232 problem recently) and am
I've recently started using Gradle and replacing my existing Maven-based projects. I have had
In a previous job we had an extensive SQLServer database that constantly had new
Well, I guess this day had to come. My client's website has been compromised
I've had quite a bit of experience with programming (three semesters teaching VBasic, C++,
I have come from WPF (MVVM) background and trying to shift to MVC 2.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.