SoFunction
Updated on 2024-11-19

Django installation and project creation in win10

The core of Django (1.4+) can run on any Python version from 2.5 to 2.7.

My computer is operating system is window10 , RAM is 4G.

1. Download django

Official Website Address./download/

The official version is Django-1.10.5. It may be updated later, and when you open it again, it may not be the version I have.

Note the places marked in red and click there to download. (The zip is about 10 megabytes or less and will download quickly)

Download complete and unzip the zip.
I unzip to drive H. H:\Django-1.10.5

2. make sure you have python installed on your machine. here i recommend to suggest to choose the latest version in the series: 2.7, install python 2.7 version.

Although Python 3.3 has been released, Django's support for Python 3 is still experimental (django1.). Because of the considerable number of non-backwards-compatible updates introduced, many of the major Python libraries and frameworks (including Python 1.4) have not yet been able to keep up.

I believe that when you want to install django, you must have some understanding of python, learn python, here I will not say python installation.

2. 1 Win+R on your keyboard, open Run, and type cmd (you surely know this one).

Go under the H drive and then under the django directory of the installer you just downloaded.

Enter the command: python install

After ENTER, it's time to start installing. Wait patiently for it to run.

As you can see in the picture below, the installation was successful.

3. Check the installation of django

Open Python's interactive interpreter .

Input:>>>import django>>>

Then you're done.

Django Request Lifecycle

Customer service (user) - > URL correspondence (route matching) - > view functions or classes (views) - > get templates (templates) and data (models) for rendering - > return customer service (user) strings

Also known as a typical MTV template

Django project creation

Download.

pip3 install django

Path (default under script in python installation directory): d:\python\Script\

cd d:\python\Script\ environment.

# Create a Django project

django-admin startprojectproject name



# Run Django functions

python  runserver 127.0.0.1:8001

 

#create app

python  startapp appplace (e.g. among winners)

Configure the template path:

(created with pycharm is templates by default)

TEMPLATES = [
        {
          'BACKEND': '',
          'DIRS': [(BASE_DIR, 'templates')],
          'APP_DIRS': True,
          'OPTIONS': {
            'context_processors': [
              '.context_processors.debug',
              '.context_processors.request',
              '.context_processors.auth',
              '.context_processors.messages',
            ],
          },
        },
      ]

Configuration of static directories:

Li (surname)

STATIC_URL = '/static/'
STATICFILES_DIRS = (
  (BASE_DIR,"static"),
)

Database creation:

Li (surname)

a. Register for the app

INSTALLED_APPS = [
      '',
      '',
      '',
      '',
      '',
      '',
      'app01',
    ]

b. Creation of databases

from  import models
     # app01_userinfo
    class UserInfo():
      # id column, self-incrementing, primary key
      # User name list, string type, specified length
      username = (max_length=32)
      password = (max_length=64)

c. Execution of orders

python  makemigrations

python  migrate

********** Note ***********

Django uses the MySQLdb module to link to MySQL by default.

To actively change to pymysql, just add the following code to the __init__ file in the project folder of the same name:

import pymysql
pymysql.install_as_MySQLdb()

This is the whole content of this article.