First App Django

Tính Phạm
4 min readJun 30, 2020

Fist, you need create virtual environment, install django to eviroment

This’s step, we are creating folder have name venv contain virtual environment

we need activate

#2. Install Django

using command to install django framework

Fist time when we use virtual environment, we need activate file by type command in this picture. Refresh editor to show folder venv created

  • manage.py: A command-line utility that lets you interact with this Django project in various ways. You can read all the details about manage.py in django-admin and manage.py.
  • The inner mysite/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. mysite.urls).
  • mysite/__init__.py: An empty file that tells Python that this directory should be considered a Python package. If you’re a Python beginner, read more about packages in the official Python docs.
  • mysite/settings.py: Settings/configuration for this Django project. Django settings will tell you all about how settings work.
  • mysite/urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs in URL dispatcher.
  • mysite/asgi.py: An entry-point for ASGI-compatible web servers to serve your project. See How to deploy with ASGI for more details.
  • mysite/wsgi.py: An entry-point for WSGI-compatible web servers to serve your project. See How to deploy with WSGI for more details.
Use command line access to children folder contain manage.py Create new app (new folder, many folder or app you want, but need do it one time)
add installed app
Add configure in list app
Create urls.py and add urlpatterns
in file detail video, define function index render to view
Create static folder contain file css, js…, create templates file contain folder and file
Add path to url template in file settings.py
add staticfiles_dir
affter add folder we need run comman python manage.py collecsttatic to apply all data, important! if you change any line code in file js, css, …in folder static, you much run command

Database setup

Important: You’ll need to run the above commands every time your models change in a way that will affect the structure of the data that needs to be stored (including both addition and removal of whole models and individual fields).

py manage.py makemigrations
py manage.py migrate

Creating models

Activating models

Psycopg is the most popular PostgreSQL database adapter for the Python programming language

run migrate again to create those model tables in your database:

run migrate again update model

Creating an admin user

Tell the admin that Question objects have an admin interface.

Writing more views

https://pypi.org/project/pylint-django/

--

--