question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

static files in production without AWS

See original GitHub issue

Note: for support questions, please use the cookiecutter-django tag on stackoverflow. This repository’s issues are reserved for feature requests and bug reports. If you need quick professional paid support for your project, contact support@cookiecutter.io.

  • **I’m submitting a … **

    • bug report
    • feature request
    • support request => Please do not submit support request here, see note at the top of this template.
  • Do you want to request a feature or report a bug?

Greetings.

I’m trying to store static on my VPS, without the help of AWS.

After I run the docker-compose -f production.yml up command, I see a message:

django_1 | 341 static files copied to '/app/habb/staticfiles'.

But, I get a 404 error, for every static file, when I go to the url.

Here are my settings in production.py


STATIC_ROOT = str(APPS_DIR('staticfiles'))

STATIC_URL = '/static/'

MEDIA_ROOT = str(APPS_DIR('media'))

MEDIA_URL = '/media/'


What am I doing wrong ?

  • What is the current behavior?

caddy_1 | 5.152.1.201 - - [20/Sep/2017:16:07:51 +0000] "GET /static/js/project.js HTTP/2.0" 404 1385

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Use project from this repo: https://github.com/narnikgamarnikus/habb

  • What is the expected behavior?

caddy_1 | 5.152.1.201 - - [20/Sep/2017:16:07:51 +0000] "GET /static/js/project.js HTTP/2.0" 200 1385

or

caddy_1 | 5.152.1.201 - - [20/Sep/2017:16:07:51 +0000] "GET /static/js/project.js HTTP/2.0" 302 1385

  • What is the motivation / use case for changing the behavior?

  • Please tell us about your environment:


# STORAGE CONFIGURATION
# ------------------------------------------------------------------------------
# Uploaded Media Files
# ------------------------
# See: http://django-storages.readthedocs.io/en/latest/index.html
'''
INSTALLED_APPS += ['storages', ]

AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = env('DJANGO_AWS_STORAGE_BUCKET_NAME')
AWS_AUTO_CREATE_BUCKET = True
AWS_QUERYSTRING_AUTH = False

# AWS cache settings, don't change unless you know what you're doing:
AWS_EXPIRY = 60 * 60 * 24 * 7

# TODO See: https://github.com/jschneier/django-storages/issues/47
# Revert the following and use str after the above-mentioned bug is fixed in
# either django-storage-redux or boto
control = 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIRY, AWS_EXPIRY)
AWS_HEADERS = {
    'Cache-Control': bytes(control, encoding='latin-1')
}

# URL that handles the media served from MEDIA_ROOT, used for managing
# stored files.

#  See:http://stackoverflow.com/questions/10390244/
from storages.backends.s3boto3 import S3Boto3Storage
StaticRootS3BotoStorage = lambda: S3Boto3Storage(location='static')
MediaRootS3BotoStorage = lambda: S3Boto3Storage(location='media')
DEFAULT_FILE_STORAGE = 'config.settings.production.MediaRootS3BotoStorage'

MEDIA_URL = 'https://s3.amazonaws.com/%s/media/' % AWS_STORAGE_BUCKET_NAME

# Static Assets
# ------------------------

STATIC_URL = 'https://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME
STATICFILES_STORAGE = 'config.settings.production.StaticRootS3BotoStorage'
# See: https://github.com/antonagestam/collectfast
# For Django 1.7+, 'collectfast' should come before
# 'django.contrib.staticfiles'
AWS_PRELOAD_METADATA = True

INSTALLED_APPS = ['collectfast', ] + INSTALLED_APPS
# COMPRESSOR
# ------------------------------------------------------------------------------
COMPRESS_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
'''

STATIC_ROOT = str(APPS_DIR('staticfiles'))

STATIC_URL = '/static/'

MEDIA_ROOT = str(APPS_DIR('media'))

MEDIA_URL = '/media/'



  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

17reactions
pydannycommented, Sep 20, 2017

Hosting static files outside of AWS S3 is outside the scope of Cookiecutter Django. Therefore, answering this requires paid support. If you are interested in that, please email us for a quote at support@cookiecutter.io.

2reactions
browniebrokecommented, Apr 11, 2019

If you select Whitenoise, you don’t need AWS S3 for static files, but it’s still needed for media files (files uploaded by users).

If your application doesn’t use Media, you can deploy your app without any S3 bucket.

Read more comments on GitHub >

github_iconTop Results From Across the Web

static files in production without AWS · Issue #1339 - GitHub
Greetings. I'm trying to store static on my VPS, without the help of AWS. After I run the docker-compose -f production.yml up command,...
Read more >
Serving static files - AWS Elastic Beanstalk
Configure static files using the console ... Open the Elastic Beanstalk console , and in the Regions list, select your AWS Region. In...
Read more >
How to deploy static files | Django documentation
The basic outline of putting static files into production consists of two steps: run the collectstatic command when static files change, then arrange...
Read more >
Serve Django Static and Media Files in ... - Ordinary Coders
Serving static and media files from the same server as your Django project during production can slow down site rendering and image loading ......
Read more >
Serving Static Files in Python With Django, AWS S3 and ...
In this article, we take a look at how to serve static files using Django, including ing examples of serving static files locally...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found