Forums

Django deploying static files

I just cloned an existing github repo and I have my project up and running for the most part. However the static files are not loading. I have gone through the django tutorial on deploying static files and the pythonanywhere tutorial as well. The images load perfectly fine, but the admin css and js as well as most of the sites css and js do not load. Is there something simple I'm missing? Any help would be greatly appreciated.

There probably is something you're missing, but there's no way for me to tell what it is from your post. To be any use to you, I'll need to know:

  • What are the static files mappings for the web app?
  • Where in your filesystem re the static files that are not loading?
  • What are the django settings that relate to static files?

MEDIA_ROOT = os.path.join(PACKAGE_ROOT, "site_media/media/")

MEDIA_URL = "/site_media/media/"

STATIC_ROOT = os.path.join(PACKAGE_ROOT, "site_media", "static")

STATIC_URL = "/site_media/static/"

STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, "static", "dist"),
    os.path.join(PROJECT_ROOT, "static"),
    os.path.join(PROJECT_ROOT, "static", "src"),
    os.path.join(PROJECT_ROOT, "Post", "static"),]

STATICFILES_FINDERS = [
     "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",]

The site is able to access the media, but not the css or the js. I then ran 'python manage.py collectstatic' and the static files were placed in the /site_media/static directory (I checked). In the static files section of the web tab I put in URL: /site_media/static and PATH: /home/soncojmk/poppin/mysite/site_media/static/admin/ which didn't work so I then put in, URL: /site_media/static and PATH: /home/soncojmk/poppin/mysite/site_media/static/admin/base.css, I hit the reload button again, refreshed the site, but there was no change. I also added URL and PATHs to the static files, but there were still no changes. In my base.html, I have {%load static files %}. All these settings work in localhost, but I understand django uses different settings in the development stage than the deployment. Thank you for the reply.

It's hard to tell from that, but I think you need a static files mapping of: URL: /site_media/static PATH: /home/soncojmk/poppin/mysite/site_media/static/

and make sure that the static files you want to serve are actually in /home/soncojmk/poppin/mysite/site_media/static/

Thank you very much. It worked! I am glad I chose Python Anywhere. I can already tell that it was the right choice.

:-)