Difference between revisions of "Django"
Jump to navigation
Jump to search
Rafahsolis (talk | contribs) |
Rafahsolis (talk | contribs) |
||
| Line 1: | Line 1: | ||
| + | = Django = | ||
==== Requirements: ==== | ==== Requirements: ==== | ||
* Python | * Python | ||
| Line 56: | Line 57: | ||
href="{% static 'cpc/css/tree.css' %}" | href="{% static 'cpc/css/tree.css' %}" | ||
href="{% url 'civilarea_history_create' task.id %}" | href="{% url 'civilarea_history_create' task.id %}" | ||
| + | |||
| + | == Reset Migrations == | ||
| + | |||
| + | 1) Fake migrations back to 0 | ||
| + | ./manage.py migrate app zero --fake | ||
| + | |||
| + | 2) Delete migrations files | ||
| + | git rm "app/migrations/*" | ||
| + | |||
| + | 3) Create new migration file | ||
| + | ./manage.py makemigrations app | ||
| + | |||
| + | 4) Pretend to run the new migration | ||
| + | ./manage.py migrate app --fake | ||
Revision as of 12:50, 8 June 2017
Django
Requirements:
- Python
- Database (MySQL / PostgreSQL...)
Installation:
pip install django
Create project
django-admin.py startproject mysite
Database Setup
Edit: mysite/settings.py
In DATABASES = {...
- ENGINE – Either 'django.db.backends.sqlite3', 'django.db.backends.postgresql_psycopg2', 'django.db.backends.mysql', or 'django.db.backends.oracle'.
- NAME – The name of your database.
- USER – Username for the database.
- PASSWORD – Password for the database.
- HOST – Database HOST.
To create the database tables execute from the project folder:
python manage.py migrate
(pip install MySQL-python)
Run App in development server
If the server is an amazon aws:
python manage.py runserver 0.0.0.0:8000
Else:
python manage.py runserver
To run server as daemon:
nohup python manage.py runserver 0.0.0.0:8000
To stop the daemon:
ps -ef | egrep python manage.py
then kill process
Create an app
python manage.py startapp appname
Create admin user
python manage.py createsuperuser access at http://serverurl:8000/admin
Usefull packages
Django Allouth
User Registration
Allouth Tutorial
Django registration
Not working in Django 1.7
User registration
Django registration step by step
Notes
Templates
href="{% static 'cpc/css/tree.css' %}"
href="{% url 'civilarea_history_create' task.id %}"
Reset Migrations
1) Fake migrations back to 0
./manage.py migrate app zero --fake
2) Delete migrations files
git rm "app/migrations/*"
3) Create new migration file
./manage.py makemigrations app
4) Pretend to run the new migration
./manage.py migrate app --fake