Page not found 404 Django media files
Add media url entry in your project urlpatterns: from django.conf.urls.static import static from django.conf import settings … urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Add media url entry in your project urlpatterns: from django.conf.urls.static import static from django.conf import settings … urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Django NewbieMistakes PROBLEM You’re using SQLite3, your DATABASE_NAME is set to the database file’s full path, the database file is writeable by Apache, but you still get the above error. SOLUTION Make sure Apache can also write to the parent directory of the database. SQLite needs to be able to write to this directory. Make … Read more
Note that this may not be safe to use for production, as S Ghosh is pointing out in a post below. But copy and paste this after running django-admin shell for example to quickly get a key. from django.core.management.utils import get_random_secret_key get_random_secret_key()
In your settings.py, there is a list called ALLOWED_HOSTS. You need to add the IP address you see in the error to that list: ALLOWED_HOSTS = [‘XX.XX.XX.XX’] Note: only add the IP address, and not the port (e.g., 127.0.0.1 and not 127.0.0.1:8000) Explanation: Django checks the Host header of the HTTP request for a url/ip … Read more
A simpler approach relies on redirection from the page LOGIN_REDIRECT_URL. The key thing to realize is that the user information is automatically included in the request. Suppose: LOGIN_REDIRECT_URL = ‘/profiles/home’ and you have configured a urlpattern: (r’^profiles/home’, home), Then, all you need to write for the view home() is: from django.http import HttpResponseRedirect from django.urls … Read more
The problem reported can be because you skipped registering the models for the admin site. This can be done, creating an admin.py file under your app, and there registering the models with: from django.contrib import admin from .models import MyModel admin.site.register(MyModel)
I think the following should work, and be simpler than Mandx’s method, although it’s very similar: Create a s3utils.py file: from storages.backends.s3boto import S3BotoStorage StaticRootS3BotoStorage = lambda: S3BotoStorage(location=’static’) MediaRootS3BotoStorage = lambda: S3BotoStorage(location=’media’) Then in your settings.py: DEFAULT_FILE_STORAGE = ‘myproject.s3utils.MediaRootS3BotoStorage’ STATICFILES_STORAGE = ‘myproject.s3utils.StaticRootS3BotoStorage’ A different but related example (that I’ve actually tested) can be seen in … Read more
I truly love this so much here is your working example! Seriously this is awesome! Start by putting this in your settings.py LOGGING = { ‘version’: 1, ‘disable_existing_loggers’: True, ‘formatters’: { ‘standard’: { ‘format’ : “[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s”, ‘datefmt’ : “%d/%b/%Y %H:%M:%S” }, }, ‘handlers’: { ‘null’: { ‘level’:’DEBUG’, ‘class’:’django.utils.log.NullHandler’, }, ‘logfile’: { ‘level’:’DEBUG’, … Read more
import settings Will import settings(.py) module of your Django project (if you are writing this code from the “root” package of your application, of course) from django.conf import settings Will import settings object from django.conf package (Django’s provided files). This is important, because [..] note that your code should not import from either global_settings or … Read more
I wanted to add a new answer because, as a beginner, the previous accepted answer didn’t make a lot of sense to me (it was only one part of the puzzle). So here’s how I store my keys both LOCALLY and in PRODUCTION (Heroku, and others). Note: You really only have to do this if … Read more