sqlite3.OperationalError: unable to open database file

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

Django – after login, redirect user to his custom page –> mysite.com/username

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

How to set-up a Django project with django-storages and Amazon S3, but with different folders for static files and media files?

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

Simple Log to File example for django 1.3+

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

Is there any difference between django.conf.settings and import settings?

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