This memo is just for me to note some important installation on Python and Django.(Based on this. Day1 to Day4)
Creation of virtual environments
Python has awesome tool to create the virtual environments which are provided different development environments for developers.
The module provides support for creating lightweight "virtual environments" with their own site directories, optionally…docs.python.org
On Windows, invoke the
venv command as follows:
C:\Python34\python.exe -m venv venv/lunch
The venv module provides support for creating lightweight “virtual environments” with their own site directories, optionally isolated from system site directories. Each virtual environment has its own Python binary (allowing creation of environments with various Python versions) and can have its own independent set of installed Python packages in its site directories.
You can deactivate a virtual environment by typing “deactivate” in your shell. The exact mechanism is platform-specific: for example, the Bash activation script defines a “deactivate” function, whereas on Windows there are separate scripts called deactivate.bat and Deactivate.ps1 which are installed when the virtual environment is created.
pip install django
So let’s understand Django
Web Server Gateway Interface
The Web Server Gateway Interface (WSGI) is a specification for simple and universal interface between web servers and web applications or frameworks for the Python programming language. It was originally specified in PEP 333
When you lunch or develop a new project, django has a command line to create new one. (you should cd to your lunch folder)
django-admin startproject lunch
and use tree cmd to take a look.
The Project Structure
The “myproject” folder is just your project container, it actually contains two elements −
manage.py − This file is kind of your project local django-admin for interacting with your project via command line (start the development server, sync db…). To get a full list of command accessible via manage.py you can use the code −
The “myproject” subfolder − This folder is the actual python package of your project. It contains four files −
- __init__.py − Just for python, treat this folder as package.
2. settings.py − As the name indicates, your project settings.
3. urls.py − All links of your project and the function to call. A kind of ToC of your project.
4. wsgi.py − If you need to deploy your project over WSGI.
│ ├── settings
│ │ ├── __init__.py
│ │ ├── base.py
│ │ ├── local.py
│ │ └── production.py
from .base import *
SECRET_KEY = ‘https://djskgen.herokuapp.com/’
DEBUG = True
DJANGO_SETTINGS_MODULE Windows is
Or yous add to venv\lunch\Scripts\activate.bat
python manage.py migrate
Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They’re designed to be mostly automatic, but you’ll need to know when to make migrations, when to run them, and the common problems you might run into.
python manage.py runserver
Congratulations on your first Django-powered page.