Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

First — what is an APP in Django? Application in Django stands for application, and when our project gets big enough, we split the functionality into separate apps. For example, a project is equivalent to xx University, and an APP is equivalent to XX College. Django itself encourages relatively independent project development, so we recommend using apps for future development.

1. Project Catalog and Document Description:

  • manage.py

Django is a command-line tool for managing Django projects.

  • __init__.py

An empty file that tells Python that the directory is a Python report;

  • settings.py

Configuration files, including database information, debugging flags, static files, etc.

  • urls.py

URL declaration for a Django project;

  • wsgi.py

Deployment server use;

  • templates

Store HTML files.

2. Understand the relationship between the project and the app:

A project is composed of multiple apps (modules).

To create a new Django app in our django project, do the following:

The first method — pyCharm

Note: The environment is in remote Ubuntu, so after the command to create the app, download it!

The second method — create by command:

(Go to the same directory as manage.py in your project!)

Python manage.py startApp App nameCopy the code

OK!

3. Using the Django framework to write Hello World!

1. Create the views.py file in the project directory.

Create a file: ② Write views.py file:

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

def test(request) :   # function view
    return HttpResponse("Hello world!")
Copy the code

2. Define the corresponding URL of the view:

3. After the service is started, enter:

IP address:8000Port/testCopy the code

The effect is as follows:

Django’s MTV model:

Django’s MTV stands for:

Model: Database-specific objects (ORMs) that are responsible for business objects and databases

Template: Holds all the HTML files

Template syntax: the purpose is to embed white variables (database contents) neatly into HTML pages

View: Takes care of the business logic and calls Model and Template when appropriate

🔆 In The End!

Start now, stick to it, a little progress a day, in the near future, you will thank you for your efforts!

This blogger will continue to update the basic column of crawler and crawler combat column, carefully read this article friends, you can like the collection and comment on your feelings after reading. And can follow this blogger, read more crawler in the days ahead!

If there are mistakes or inappropriate words can be pointed out in the comment area, thank you! If reprint this article please contact me for my consent, and mark the source and the name of the blogger, thank you!