-
A migration allows us to move databases from one design to another, this is also reversible
-
$ django-admin startproject stratos
-
$ python manage.py runserver
-
$ python manage.py startapp first_app
-
init.py
Blank python script, python know that this directory can be treated as a package -
admin.py
We can register our models here which Django will then use them with Django's admin interface -
apps.py
Application specific configurations -
models.py
store the application's data models -
tests.py
store test functions to test our code -
views.py
functions that handle requests and return responses -
Migrations folder
stores database specific information as it relates to the models -
{{}} used for simple text injection
{%%} used for more complex injections and logic -
Django comes equipped with SQLite
-
$ python manage.py migrate
-
Register the changes to our application
$ python manage.py makemigrations first_app
$ python manage.py migrate -
$ python manage.py shell
>>> from first_app.models import Topic >>> t = Topic(top_name="Social Network") >>> t.save() >>> print(Topic.objects.all()) >>> quit()
-
$ python manage.py createsuperuser
-
Faker library to create script that will populate our model with some dummy data
-
Django - MTV (Models-Templates-Views)
-
Cross-Site-Request Forgery (CSRF) token, which secures the HTTP Post action that is initiated on the subsequent submission of a form. {% csrf_token %}
-
{{ form.as_p }} – Render Django Forms as paragraph
-
Relative URLs with templates Method-1:
<a href="{% url 'thanku' %}">Thanks</a> name='thanku' is in the urls.py file
Method-2:
<a href="{% url 'first_app.views.thanku' %}">Thanks</a>
Method-3:
<a href="{% url 'first_app:thanku' %}">Thanks</a> this method requires that app_name variable to be created inside the urls.py file
-
URL Template Inheritance or Template extending is extending the base.html to other .html files
-
base.html
<body> {% block body_block %} Anything outside of this will be inherited if you extend! {% endblock %} </body>
-
other.html
<!DOCTYPE html> {% extends "first_app/base.html" %} {% block body_block %} <HTML specific for other.html> <HTML specific for other.html> {% endblock %}
-
-
General form for a template filter
{{ value|filter:'parameter' }} -
Django Password PBKDF2 algorithms with a SHA256 hash, built-in to Django
$ pip install bcrypt $ pip install django[argon2]
-
Topics to learn
- ORMs
- Advanced User Authorization
- Socail Login
- Payment
- REST APIs
- Encryption
- Testing
- Sessions
- Cookies
- Class-Based Views
-
WSGI Servers
A Web Server Gateway Interface (WSGI) server implements the web server side of the WSGI interface for running Python web applications. -
What is an ORM? Object-Relational-Mapper Depending on the ORM you get a lot of advanced features out of the box, such as support for transactions, connection pooling, migrations, seeds, streams