Django for-programmers_1

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.

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.

Lunch

cd venv\lunch\Scripts\activate.bat

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.

install Django

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 −

  1. __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

local.py

from .base import *
SECRET_KEY = ‘https://djskgen.herokuapp.com/
DEBUG = True

DJANGO_SETTINGS_MODULE Windows is

set DJANGO_SETTINGS_MODULE=lunch.settings.local

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

http://127.0.0.1:8000/

It worked!
Congratulations on your first Django-powered page.

A single golf clap? Or a long standing ovation?

By clapping more or less, you can signal to us which stories really stand out.