Recently I hosted my django website on EC2 ubuntu Instance with nginx server on AWS. When I open my admin page of this website IT is looking very ugly and there is not css but on local server 127.0.0.0:8000 it works fine.
I also inspect on browser console, It is giving this error:
GEThttp://jassem.in/static/admin/css/dashboard.css
[HTTP/1.1 404 Not Found 51ms]
The resource from “http://jassem.in/static/admin/css/nav_sidebar.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http://jassem.in/static/admin/css/base.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http://jassem.in/static/admin/js/nav_sidebar.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http://jassem.in/static/admin/css/responsive.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http://jassem.in/static/admin/css/dashboard.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
How can I get back my previous django admin page. FYI I am a newbie on web technology and Django
if the problem apply on all the pages of your project try collectstatic,
Django provides a command to collect static files from all applications
into a single location. This simplifies the setup for serving static files in production.
Open the shell and run the following command:
python manage.py collectstatic
You will see this output:
165 static files copied to '/yourproject/static'.
Files located under the static/ directory of each application present in the
INSTALLED_APPS setting have been copied to the global /yourproject/static/ project
directory.
then, edit the config/nginx.conf file and add:
location /static/ {alias /home/projects/yourproject/static/;}
location /media/ {alias /home/projects/yourproject/media/;}
after the lines:
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass yourproject;
}
replace the /home/projects/yourproject/ path with the absolute path
to your project directory
You need to run the collectstatic command:
SSH into your EC2 instance
Run python manage.py collectstatic
Assuming you have set up your static files correctly, it should work after that.
Try running this command
python manage.py collectstatic
if it does not work, try this then
python manage.py collectstatic --no-input
This was my first deployment and I tried many things. Finally, this is what worked for me:
Running python manage.py collectstatic
Finding the nginx.conf file and within the server{} block, adding: location /static/ {alias /home/projects/yourproject/static/;} then runinng sudo service nginx restart from the bash terminal
In my settings.py file adding: STATIC_ROOT = os.path.join(BASE_DIR, 'static') and STATIC_URL = '/static/'
just turn on your DEBUG mode in the setting.py file and it will work just fine.
DEBUG = True
Related
I am developing a Django site on an Ubuntu 16.04 LVM using Apache and mod_wgsi. When I try to load one of my pages, all the static files give a 404 not found error. I believe I have my settings set correctly because
python3 manage.py findstatic
is able to find the files and running the development server with DEBUG=off and the --insecure flag, It still works correctly. Does this mean it is an issue with apache?
Here are my static file settings:
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
#'/home/matt/jukebox/bin/jukebox/static/'
)
Does anybody know what could be wrong? The files were being served previously, but after updating my server and the code for the site, it stopped serving.
Thank You
Adding this to my apache config file fixed the issue:
Alias /static /home/user/myproject/static
<Directory /home/user/myproject/static>
Require all granted
</Directory>
I found the answer here:
https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04
Still not sure why it had been working previously without these settings, but hopefully this answer can help someone.
When running Django in local mode using the runserver command video files are not loaded in the browser properly. I get the error
An error occurred trying to load the resource.
All other static files serve fine such as images, javascript and css.
I have found the answer finally, Django's runserver does not support byte range requests. See this thread:
https://groups.google.com/forum/#!msg/django-developers/NZ1qTkZ6vok/fhdz7rTtL1EJ
And this ticket:
https://code.djangoproject.com/ticket/22479
Try running
python manage.py collectstatic
Of course you must have STATIC_ROOT and STATICFILES_DIRS set properly in your settings file.
So I've seen alot about Apache not serving Django admin static files, but for some reason, Apache is not serving any static files. It understands and finds the templates, but no images, css, or javascript is loaded.
EDIT 2: Updated the two files to show new settings
EDIT: I added the STATIC_ROOT and I was able to collectstatic files, but it still doesn't serve them after server restart.
I've tried ./manage.py collectstatic and get this error:
ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without
having set the STATIC_ROOT setting to a filesystem path.
My settings.py file is here:
https://github.com/rchurch4/stackquestions/blob/master/settings.py
My nxt4.com.conf file is here:
https://github.com/rchurch4/stackquestions/blob/master/nxt4.com.conf
If someone could please let me know exactly how to configure this so that Apache will serve django's static files, that would be great. I'm running Ubuntu on AWS with a mysql db. The filepath to the site on the server is: /home/ubuntu/nxt4.com/nxt4/
Thanks in advance
The error message seems quite clear: you have not set the STATIC_ROOT setting, so collectstatic does not know where to put the collected files. From the looks of your httpd.conf, it seems like it should be set to "/home/ubuntu/nxt4.com/static/"
I have a Mac running OS X 10.9.3. I am trying to setup a Django application backed by a PostgreSQL database served by gunicorn, with static assets served by NGINX. I'm an old hand at Django with MySQL running with the developement server (manage.py runserver). But I'm new to setting it up with virtualenv, gunicorn and NGINX. So I'm following the instructions here.
My Django Project is being served successfully at localhost:3026. As a test of the database connectivity, I wanted to take a look at the Django Admin interface. I visited localhost:3026/admin/
I have included a screenshot below.
Why does this admin page look so ugly? It lacks the neccessary graphical interface and css that it is supposed to have? It looks like NGINX is not properly serving up those static assets. How can I troubleshoot and fix this issue?
EDIT:
After I posted this question, I did python manage.py collectstatic. That went and successfully copied all the static files to where they were supposed to (I think?) live in /opt/myenv/static. You can see the output of that command here. I then re-started gunicorn and nginx. I thought that would fix it. But unfortunately it didn't. The issue remains. In my Django settings.py file, I have configured the STATIC variables as follows:
STATIC_ROOT = "/opt/myenv/static/"
STATIC_URL = '/static/'
Try run command,
python manage.py collectstatic
If the commands executes successfuly, the static file would be generated in your project path, and then if you config the right static path, the web page will be correct.
I'm trying to get a fresh installation of Django 1.5 running on an Apache-Server. The WebServer is situated on a shared hosting platform called uberspace.de
which means I have no access to the Apache configuration itself I can however write .htaccess files if that's any help at all. Django is deployed via fast-cgi which is working as expected.
Whats not working however is the access to static files on the server like the .css files and graphics for the Django administration interface.
As mentioned in the official docs I used the following command to copy the static Files into my ~/html/static directory.
manage.py collectstatic
And these are the values from my settings.py:
STATIC_ROOT = '/home/bier/html/static/'
STATIC_URL = '/static/'
All I get is the infamous django 404 page when I try to access any of these Files.
I also followed the 'How to install and deploy Django' guide on my Webhosters Website to the letter. (sorry its only available in german I believe)
I already contacted the webhosters support but they don't know whats wrong.
All the solutions I've come up with so far suggest setting some sort of Alias in the Apache configuration. Which I can not do.
I'm thankful for any ideas you might have.
Try using a full address instead.
STATIC_ROOT = '/home/bier/html/static/'
STATIC_URL = 'http://www.mysite.com/static/'
Edit: Perhaps you could ask your host to setup /static/ in your Apache config:
sudo nano /etc/apache2/sites-enabled/mysite.com and add:
Alias /static/ /home/bier/html/static/
I've had a situation before where I've had to upload /static/ files manually because of a highly restrictive host (permissions). Perhaps you need to download a copy of django to your desktop and then upload the static admin file set into your /static/ directory manually?
Lastly, have you added the static files to your urls?
url(r'^static/(?P<path>.*)$','django.views.static.serve',{'document_root': '/home/bier/html/static'}),
I have more simpler solution. you need to create a directory named, let's say 'x' in "public_html" or similar location from which server serves the files by default.
Then upload all static files in directory x. (this can be done by running collectstatic locally and then upload all contents of directory STATIC_ROOT to x)
Then, change your STATIC_URL and STATIC_ROOT as follows:
STATIC_URL = '/x/'
STATIC_ROOT = os.path.join(BASE_DIR, '../public_html/x') # Path to folder