Xiaobai Learning Django First Station-Environment Configuration


Django is simplyusePythonDeveloped oneFree Open SourceWeb Framework

Using Django enables you to build and maintain high-quality Web applications at minimal cost.

Open up!!!

Tool preparation:

linux(ubuntu) + python3.6 + pycham + mysql

First, create a virtual environment in the virtual machine.

mkvirtualenv -p /usr/bin/python3 django_test


Install the Django we need (I chose Django version 2.1.0)

pip install django==2.1.0

New project django_test

django-admin startproject django_test

Then check it out.

There’s an additional django_test folder. Let’s take a look at the structure of this file.


  • Manage.py: A command-line tool in Django for managing Django projects
  • _ init_.py: Empty file, tell python that this directory is a python package
  • Set.py: Configuration file, including database information, debug flags, static files, etc.
  • Urls.py: URL declarations in Django projects
  • Wsgi.py: Used for deploying servers

Next, synchronize pycham

New projects

click here

Connect the virtual connection interpreter, fill in the information, and click Next

Enter your password and click Next

Find the interpreter location

Click Create


Upload Settings

Directories in the corresponding virtual machine

After clicking ok, you can synchronize the project you just created in the virtual machine to the local location.

Configure native Django settings

Set ALLOWED_HOSTS= [] in set.py to ALLOWED_HOSTS= [‘*’]

Open Server 1

Enter the django_test file in the virtual machine and enter it again

python manage.py runserver

Local browser input

Then we can see a small rocket!

Open Server 2

click here

Set to

Re-enter settings to set Django

Click ok, Django is set

After clicking on the green triangle to start, you can see the small rocket by typing into the browser.

Now let’s start creating view functions

Create a view.py file in the project directory (request is required)

Add routing to urls.py

Then go to the browser and enter

So we got our first page.

Then we created the first app:book for our project.

Method 1: You can enter it from the virtual machine command line

python manage.py startapp book

Method 2: Click here in pycham

Enter startapp book

Synchronize the directory and you’ll have our book app.

At this point, our first stop in learning Django is over.

Recommended Today

The construction tool of C ා

What’s the motivation for writing this article? Why do you want to study the build tool (see. Csproj), create a new C project with visual studio IDE, and click build to run it? A: please refer to this_minutes_before_coding. I call it “engineering.”. Engineering development is not just about opening IDE and creating new projects. It […]