Question

I am trying to upload my Django App to Bluehost and for some reason none of the CSS is working on the admin page, I have been touring the web for hours looking for solutions but I haven't found any specifically tailored to Bluehost or Django 1.6. This Question was the closest thing to what I need but it still isn't working. Django's admin is missing css, images, etc - unable to properly set up static files on shared host All of my static files are now in /public_html/static/, it worked for that person so I am curious to know what I am doing wrong.

Here is the pertinent code

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
MEDIA_ROOT = '/home/mySite/Django/WebApp/quiz'
MEDIA_URL = '/media/' 
STATIC_ROOT = '/home/mySite/public_html/QuizApp/static/'
STATIC_URL = '/static/' 
ADMIN_MEDIA_PREFIX = '/static/admin/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

After I edited settings.py I did run collectstatic. Also I feel like this may be important as well.

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'tempaltes')]

and the .htaccess file because Bluehost doesn't allow you to access the httpd.conf file

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !^/static/
RewriteRule ^(.*)$ QuizApp.fcgi/$1 [QSA,L]

If you all need anything else let me know. This is my first experience with web development, python, and CSS in general so please be as detailed as possible I literally know nothing.

Was it helpful?

Solution

If you copied and pasted your code directly from your files, then the first thing you might try is correcting the typo in your template_dirs assignment.

You have:

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'tempaltes')]

It should be:

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

Also, you might check whether your STATIC_ROOT is set accurately.

It should be:

STATIC_ROOT = '/home/<user>/public_html/subdirectory/static/'

Your subdirectory looks fine (QuizApp), but it looks like you have the name of your project site 'mySite' where your username should be. With bluehost you want your static_root to be /home/username/...

UPDATED ANSWER:

Your STATIC_ROOT is the full-path to the directory where your static files will be moved to and stored (when you run collectstatic). Your STATIC_URL is the url your app will refer to when sourcing static files. With bluehost, anything in a file path after '/public_html/' is accessible by the web. This means any folder after '/public_html/' can/must show up in a url (after your domain name) pointing to any file in that folder.

In this case your STATIC_ROOT is '/home/mySite/public_html/QuizApp/static/' but your STATIC_URL is '/static/', so it looks like your url is pointing to the wrong place.

So, if for example, your domain name is "coolsite.com", then your static files are being stored in 'www.coolsite.com/QuizApp/static/' but the url you're pointing to is just 'www.coolsite.com/static/'. So try changing your STATIC_URL to '/QuizApp/static/' and then run 'python manage.py collectstatic' again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top