0

I'm having alot of trouble either understanding how to properly host my static files on both local and heroku. Currently when Debug is turned off, I get an error 500- otherwise it works fine.

I've read quite a few SO posts but so far, no solution has helped. I've also tried to host staticfiles on AWS, but this has still not helped.

Edit I currently get a 500 error on any page but the admin console.

Error from django server:

[27/Nov/2019 13:36:07] "GET / HTTP/1.1" 500 9061

Error from web console:

Failed to load resource: localhost1/: the server responded with a status of 500 (Internal Server Error)

Below is my code:

settings.py

INSTALLED_APPS = [
    'widget_tweaks',
    'django_select2',
    'masterform',
    'tempus_dominus',
    'team',
    'sms',
    'opportunities',
    "rest_framework",
    'import_export',
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
]

STATIC_URL = '/static/'

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



STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, "live-static", "static-root")

urls.py

from django.views.static import serve
from bdsurveyapp import settings

urlpatterns = [
    url('', include('opportunities.urls')),
    url(r'^sms/', include('sms.urls')),
    url(r'^admin/', admin.site.urls),
    path('accounts/', include('django.contrib.auth.urls')),
    url(r'^dashboard/', include('dashboard.urls')),
    path('login/', auth_views.LoginView.as_view(template_name='pages/login.html'), name="login"),
    path('logout/', auth_views.LogoutView.as_view(template_name='pages/logout.html'), name="logout"),
    url(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}),
]

partial base.html

<!DOCTYPE html>
<html lang="en">
{% load static  %}

<head>
  {{ form.media.css }}

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">

  <link rel="apple-touch-icon" sizes="180x180" href="{% static 'img/apple-touch-icon.png' %}">
  <link rel="icon" type="image/png" sizes="32x32" href="{% static 'img/favicon-32x32.png' %}">
  <link rel="icon" type="image/png" sizes="16x16" href="{% static 'img/favicon-16x16.png' %}">

  <link rel="manifest" href="{% static 'img/site.webmanifest' %}">
  <link rel="mask-icon" href="{% static 'img/safari-pinned-tab.svg' %}" color="#5bbad5">
  <meta name="msapplication-TileColor" content="#da532c">
mg2019
  • 191
  • 17

1 Answers1

0

I had a similar issue and I found that when I commented out 'django.contrib.staticfiles' in INSTALLED_APPS my issues were fixed.

carousallie
  • 776
  • 1
  • 7
  • 25