shorefoki.blogg.se

Static loading
Static loading






static loading

When DEBUG is enabled Django uses STATICFILES_FINDERS option that by default is: [ Since you have '' in your apps list, Django actually does NOT load files from STATIC_ROOT when DEBUG is True.

  • (optional) wipe your STATIC_ROOT folder.
  • move your folders img and css to the folder created in step 3.
  • In your case, the problem was that you put static content into the STATIC_ROOT which is a folder Django wont look for content in debugging mode.Īdmin and ckeditor work because they follow step 2., thus their static files actually come from the folder of the installed app and not from your static folder when in debugging mode. If you are in debugging mode you are done after step 3. and 3.) and puts them into the folder you created in 1.
  • For production run collectstatic so that Django collects your static files (from points 2.
  • Obviously you can choose another name, static_files is just a suggestion.
  • For static files that do not directly belong to an app, create the folder static_files within your project and add to your settings: STATICFILES_DIRS =.
  • Put static files specific to an app into the folder static inside the app.
  • Don't ever put anything yourself into the folder you specify as STATIC_ROOT.
  • This is an easy approach for handling static files in django (that works out of the box if you use Django default options): Urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) Urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

    static loading

    Path('ckeditor', include('ckeditor_uploader.urls')), MEDIA_ROOT = os.path.join(BASE_DIR, 'media')įrom import static STATIC_ROOT = os.path.join(BASE_DIR, 'static') In an effort to help anyone debug my problem, here are some relevant excerpts files:īASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(_file_))) This is to be expected though, since in development I don't have a web server to handle this (to clarify, I usually run the server in debug mode, but have tried turning this setting off and on to see what changes occur) Running with DEBUG=False works fine in production (all the static files load) but no static files load at all when DEBUG=False in development.I have run collectstatic in both environments.I am using the template tag and I've tried that too.I have routed media in much the same way (see the settings file below) and that works fine in development.It works fine in production! I assumed this was because I had dedicated aliases in my apache config, but that doesn't explain why admin and ckeditor work.Here's some other information which may be of interest:

    static loading

    Here's an example from the runserver output in debug mode (the file at static/css/base.css exists in my file tree): GET /static/ckeditor/ckeditor/ckeditor.js HTTP/1.1" 200 690627 Here's a map of my directory: rootĪs stated, ckeditor and admin load fine while the others do not. In my development environment my Django app will not load some of my static files, specifically ones that I have added myself: that is, the two packages I've added to my app ( admin and ckeditor) are both loading up fine, but two of the folders I've created and linked myself ( img and css) are not being found. Usually I have this issue exactly the other way around!








    Static loading