Released · improving
Framework · Since 2005
Django is a full-stack Python web framework for building database-backed web applications quickly, with an ORM, an admin site and authentication built in.
Django is an open-source web framework written in Python. It was released in 2005 and is now maintained by the non-profit Django Software Foundation. It follows an MTV (Model, Template, View) structure and ships with most of what a web service needs, including URL routing, an ORM, a template engine, forms, authentication and an admin interface, which is why it is often called a batteries-included framework.
Django is especially strong for database-centric services such as content management systems, internal business tools, e-commerce sites and REST API backends. Define your models as Python classes, let migrations create the tables, and manage the data right away in the automatically generated admin. Protection against common attacks such as CSRF, SQL injection, XSS and clickjacking is enabled by default.
If you are new to Django, create a virtual environment, install Django with pip, and work through the official polls tutorial from start to finish. Once you have defined a model, run a migration and wired a view to a template, you can look up the rest of the framework in the reference as you need it.
Define models as Python classes to query and save data without writing SQL; when models change, makemigrations and migrate keep the database schema in step.
Register a model and you get an admin interface for searching, adding, editing and deleting records, so you rarely need to build back-office tools yourself.
CSRF protection, automatic HTML escaping in templates, parameterized queries and strong password hashing are all on from the start.
Built-in user, group and permission models, login views, and forms and model forms that validate input.
Create and activate a Python virtual environment in your project folder. The command below is for macOS and Linux; on Windows, activate it with .venv\Scripts\activate.
python -m venv .venv && source .venv/bin/activateInstall Django with pip inside the virtual environment. Afterwards the django-admin command is available.
python -m pip install DjangoCreate a new project with django-admin, start the development server, and open http://127.0.0.1:8000 in your browser.
django-admin startproject mysite && cd mysite && python manage.py runserverReplace the mysite/urls.py generated by startproject with the code above and you have the smallest Django app: it returns Hello, world! at the root URL. A view is a function that takes a request and returns an HttpResponse, and urlpatterns maps URLs to views. The development server restarts automatically when the code changes.
mysite/urls.py
from django.http import HttpResponse
from django.urls import path
def hello(request):
return HttpResponse("Hello, world!")
urlpatterns = [
path("", hello),
]
django-admin startproject mysite && cd mysite && python manage.py runserverSix chapters that take you from installation to the core ideas of Django.
Ask questions, share experience and trade opinions about Django.
No discussions yet. Start the first one.
0 comments
Sign in · Sign in to leave a comment.
Be the first to comment.