Related cards:
django apps in subfolder
sample manage.py
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
# Add the apps directoriy to Python's path. In production it will
# be n...
django rename app
Before renaming
Always migrate databases before changing the app name.
manage.py makemigrations
when you see the following message then it is safe to proceed with renaming the app.
No changes detected
Fixed table names
...
django tables2 installation
Django-tables2 is Available on pypi and can be installed using pip:
pip install django-tables2
After installing, add 'django_tables2' to INSTALLED_APPS and make sure that 'django.template.context_processors.request' is added to the context_proces...
django DRF Permissions
Settings
global settings for a REST framework API are kept in a single configuration dictionary named REST_FRAMEWORK.
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for una...
django sitetree install
- Add the sitetree application to INSTALLED_APPS in your settings file (usually ‘settings.py’).
- Check that django.core.context_processors.request is added to TEMPLATE_CONTEXT_PROCESSORS in your settings file. For Django 1.8+: django.template....
django SessionAuthentication
Overview
SessionAuthentication method: This method uses the session cookie (which is set through the normal Django login and logout views) to check out if there’s an authenticated user and get his username. This method works only in the same s...
django static javascript files
Background
Websites generally need to serve additional files such as images, JavaScript, or CSS. In Django, we refer to these files as “static files”. Django provides django.contrib.staticfiles to help you manage them.
Typical use
Usually th...
django management commands
Management Commands
Add a management/commands directory to the application. Django will register a manage.py command for each Python module in that directory whose name doesn’t begin with an underscore.
Example
from django.core.manageme...
django transaction.set_autocommit(False)
example from: stackoverflow
from django.db import models
from django.db import transaction
class MyModel(models.Model):...
django apps in subfolder
Given a sub-directory named "apps" for all django applications, the following steps are used to setup the sub-directory and create apps.
1 create app sub folder - "apps"
mkdir apps
touch apps/__init__.py
2 add app to sub folder:
...