Django's simple command and implementation of the first page

Keywords: Python Django Database shell

1, Create a python virtual environment and install django

2, Create a django project

Command: Django admin startproject project name


G:\django_learn>workon testvir
(testvir) G:\django_learn>django-admin startproject django_learn

After execution, a django project will be created successfully and the directory will be generated

--- django_learn

    Contains the default settings for the project, including database information, debug flags, and other working variables
    Responsible for mapping URL patterns to applications
    Be responsible for the launch of the project
    Tools in Django project, through which you can call django shell, database, etc.

3, Create an app

Command: python startapp application name


(testvir) G:\django_learn\django_learn>python startapp blog

(testvir) G:\django_learn\django_learn>dir

Successfully created an app named blog containing
    View operation file

4, Making the first page with django

  1. Configure file to import app

    'blog'  # Import blog into
  2. Configure file, set route

    from django.conf.urls import url
    from django.contrib import admin
    from blog import views
    urlpatterns = [
    url(r'^time_show/', views.time_show),
  3. Configure, set views

    import time
    from django.shortcuts import HttpResponse
    # Create your views here.
    def time_show(request):
    return HttpResponse(time.asctime())

5, Launch django project
Command: python runserver
Default port 8000

(testvir) G:\django_learn\django_learn>python runserver
Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python migrate' to apply them.
May 03, 2018 - 22:54:14
Django version 1.9.8, using settings 'django_learn.settings'
Starting development server at
Quit the server with CTRL-BREAK.

Enter in the browser/
As shown in the figure below

Posted by dannylewin on Mon, 23 Mar 2020 08:51:47 -0700