Django Debug Toolbar style is broken - python

I have installed django debug-toolbar, it can fetch the css and js but it still shows debug toolbar like below and also shows this at the end of the page instead of nearby, there is not js error in console. Any ideas?

I was having this exact same issue. You don't need to switch to serving files locally, using S3 to serve your static files works just fine.
In my case (and likely in yours), you just need to run:
$ python manage.py collectstatic
That will update the static files—adding the files that the Debug Toolbar needs to render its styling correctly.

Related

Flask static files error: Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH

I have a working python 3.9 Flask app. The latest Pycharm is my IDE. Yesterday I created a new app with a very similar structure. The old app runs and finds/loads all static content just as expected when run through the PyCharm debugger or from the command line with flask run.
The new app will "run" from PyCharm or flask run. It loads the main/home blueprint and serves the correct template. What it does not do is serve any css or js resources in the static folder. Rather, it tries to load them but each resource in the Brave developer tools window has the message:
Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH
I have surveyed the file sizes for each css and js file. I have matched the lengths against the developer tools "network" tab response information and it looks like all the sizes match.
I have tried this with FireFox and it just says:
Loading failed for the <script> with source “http://127.0.0.1:5000/static/LIB/jquery/jquery.min.js”.
and the other resources.
I have deleted and recreated the node_modules and the .idea dirs.
Ideas?
Sigh, my problem was with setting the USE_X_SENDFILE Flask config variable. The dev server does not support it and honestly I don't know why I even included it. Removing it fixed my issues.
Thanks entirely to this post:
Flask development server with X-Sendfile

Css file not loading on Python Anywhere

I have recently begun making a Django project on PythonAnyhwere.
I have followed the entire tutorial provided by Django for including static files on the project. I have observed the programs work fine on a site with http, but does not work on a site with https.
What could be the reasons and how can I overcome this problem?
Edit : The site is working now, apparently, but I would still like an explanation as to why it WAS working differently, if anyone can provide.
to load your CSS files (or totally static files), you need to follow the steps below:
1- inside settings.py
STATIC_URL = '/static/'
STATIC_ROOT=os.path.join(BASE_DIR,'static')
MEDIA_ROOT=os.path.join(BASE_DIR,'media')
MEDIA_URL='/media/'
2-collect static files using bash console
python manage.py collectstatic
3-you need to enter the Static files directory inside the web tab
check the image below
static files python anywhere
4- reload your web app

Django: unable to locate static files folder

I am trying to setup an AS2 server using the python package django-pyas2 (https://github.com/abhishek-ram/django-pyas2)
Everything has been working fine while I was using the runserver command, but when trying to host my web app using IIS(10), I've noticed that none of my static files get loaded when loading a page.
I've been on countless forums/documentations and I know that I need to setup my IIS to serve these files, but I haven't been able to answer a rather stupid question:
Where is the /static/ folder of django-pyas2 located ???
There is no such folder on the github page.
When using the runserver command, django somehow manages to find all the static files (.css, .js, .png) from the static folder, but I am still totally clueless to where that folder is actually stored.
I've been searching in these locations to no avail: (I'm using a virtual env on Windows Server 2016)
my own project
my venv's site-packages\django-pyas2 folder
in C:\Python37\Lib\site-packages\django-pyas2
in C:\User\AppData\Roaming\Python\Python37\Lib\site-packages\django-pyas2
I've also tried to use the command collectstatic, but I first need to know where the actual /static/ folder is stored.
I've double-checked, and the files are apparently stored locally and not on a CDN. This is driving me kind of nuts, and I could definetly use some help from someone!
A big thanks in advance ❤
EDIT:
my IIS wfastcgi configuration
my IIS advanced settings
I'm not sure about how IIS(10) works but this is usually the fix.
go to settings.py and add a path for your static files.
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')#new
Next on the console (command prompt/ terminal/shell) run
python manage.py collectstatic
This should work
OK, so I finally found the static folder I was looking for in this location:
<PYTHON_PATH>\Lib\site-packages\django\contrib\admin\static
I believe the django_pyas2 package is using some default js/css already included with Django, and I couldn't find it because it was burried in Django's files.
For those encountering the same problem, here are the steps I then took to make it work with IIS(10):
copy/pasted the static folder from the django package to my project's root
went to IIS manager, right clicked on my website > Add Application
for the application alias: "static", for the path: <path_to_static_folder>
/!\ IMPORTANT /!\ left clicked on newly created "static" application, went to Mapping Manager, and then deleted the associated FastCGIModule
Didn't have to do anything in settings.py, nor execute the collectstatic command.
Works fine after that!
Thanks for trying to help.

Django - Apply changes in HTML & Static files without restarting dev server

I am working in a dev environment using the built in Django web server. One of the inconvenience that I have is everytime I make changes in HTML or Static files it does not apply when I reload the browser until I kill the dev server and run again.
python manage.py runserver localhost:8000
Is there a way so Django will reflect the changes instantly? Thanks in advance
Django reload the server only on changes on .py files. I read different ways to trigger reloading (such as installing a third party app, tweaking caching depending on whether DEBUG = True, etc etc).
The easiest and dumbest way is to make an insignificant slight change in the view you're working on (say, adding a #, removing it) after you edited and saved your template. It is dumb but it works.

What are the problems with loading CSS and JS from Django to IIS7?

I successfully deployed my Django site to IIS7 but I still have problems about how to configure IIS to serve the static files. I tried many many things from the internet but nothing seems to work. Everything is working fine on Django server (manage.py runserver) and with debug = True, but as soon as I turn off debug (debug = False) and open it on IIS, the bootstrap css and js are not loaded.
Do you have any ideas about why I'm experiencing this behavior? Perhaps you could point me to a step-by-step guide to help me?
Right click on your website in IIS7 manager and
add a virtual directory
name it with the same name of your folder you want IIS to handle. lets say static
add the path to your real static folder in your application mine was in myproject/static then ok
and here you go :)
If you are using django >= 1.3 and following the doc you are probably using the 'staticfiles' app.
First, you must configure your II7 to serve static files from the chosen path, by default URL: /static/ and PATH /staticfiles/ (I have no experience with II7 but the conf should be straightforward)
Then run ./manage.py collectstatic to move the static files into the correct path
and you should be done...
More info on production settings here.
You also need to insert a web.config file into the static directory for IIS to serve the files.
See: Django Static Files - 404

Categories