I am using angular heroku and django. I have been noticing that when I use 'ng build' to build new static files to add to django then push to heroku, the heroku instance is showing a website that is several versions behind what my current code is.
I attempted to run my django local server today after doing ngbuild
placing my files in the designated folder,
running python manage.py collectstatic
which it runs successfully.
then I run my django server, navigate to my page and I get a 500 response.
Because I am using angular, I have set up my django server as a rest backend.
every endpoint the rest service uses starts with the url api/
so localdomain/api/ <-- restful service
localdomain alone serves the angular app.
I only receive the 500 sever error when I try and get the app served.
Here are all my settings regarding static files:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
#angular distro root
ANGULAR_APP_DIR = os.path.join(BASE_DIR, 'frontend/dist/')
#image distro root
ASSETS_DIR = os.path.join(BASE_DIR, 'frontend/dist/assets/')
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
#STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(ANGULAR_APP_DIR),
os.path.join(ASSETS_DIR),
]
my template settings:
ROOT_URLCONF = 'suitsandtables.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['suitsandtables/templates',
'stemail/templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
my url to serve static files and my url to render the index.html page
url(r'^(?!/?static/)(?!/?media/)(?P<path>.*\..*)$',
RedirectView.as_view(url='/static/%(path)s', permanent=False)),
url(r'^$', views.RootView.as_view()),
my rootview class to render the index.html
class RootView(TemplateView):
def get(self, request, **kwargs):
return render(request, 'index.html', context = None)