程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Imustlost website development - Practice 1 [imustlost] [self learning and development project series] [Django] [MySQL] [HTML] [CSS] [JavaScript] [jqurey]

編輯:Python

【 Preface 】 Record of actual combat experience

Participated in a project led by a big man ——IMUSTCTF,Oj After the project of system development, I learned a lot of development technology .
However, compared with the complete technology required for website development, there are many technologies that will not , So I explore the complete website development technology in my spare time .

Development process notes

One , establish django Files and app file 【 You need to complete the second step first mysql Installation and configuration of 】

There are records in the previous note file :
【Django frame 】 Learning and its 【 Database docking technology 】 Study && Development Notes 【 Introduction 】

Two , install mysql

Address :https://dev.mysql.com/downloads/mysql/

The latest is 8.0 edition , I chose the last latest one mysql-5.7.24-winx64.zip

zip The format is to decompress by yourself , After decompression, actually MySQL You can use it , But you need to configure environment variables zip The format is to decompress by yourself

My computer -> attribute -> senior -> environment variable

choice Path, Add after : Yours mysql bin Path to folder :
I am a win10 System , Be the same in essentials while differing in minor points , There was no screenshot , So steal other people's pictures

After configuring environment variables , stay F:\mysql\mysql-5.7.24-winx64\mysql-5.7.24-winx64 Add a new configuration file under the directory mysql.ini , At the same time bin Create a DATa Folder ( Used to store database data )

mysql.ini The contents of the document are as follows

[mysql]# Set up mysql Client default character set default-character-set=utf8 [mysqld]# Set up 3306 port port = 3306 # Set up mysql Installation directory basedir=F:\mysql\mysql-5.7.24-winx64\mysql-5.7.24-winx64# Set up mysql Database data storage directory datadir=F:\mysql\mysql-5.7.24-winx64\mysql-5.7.24-winx64\data# Maximum connections allowed max_connections=200# The character set used by the server defaults to 8 Bit coded latin1 Character set character-set-Server=utf8# The default storage engine that will be used when creating a new table default-storage-engine=INNODB

open cmd, You don't need to go to the installation directory (∵ Environment variables have been configured before ), Enter the following command , enter , No response


Enter the following command , enter , It will prompt that the installation is successful

mysqld install


Start the service , Enter the following command , enter , After successful startup, it is shown in the figure below

netstart mysql


After the service starts successfully , Enter the command when you need to log in ( No password for the first login , Press enter directly to pass )

mysql -uroot-p

Change Password ( Must be started first mysql), Execute the following command and enter ,enter password Come back , The password is usually set to root, Convenient memory

mysqladmin -u root -p password


installed mysql recommend :
Both software are particularly easy to use , Choose one .【 Baidu crack method 】
open Navicat Connect mysql This software is more convenient , Not too much configuration ,sqlyog Need configuration .【 The details are simple 】

3、 ... and ,Django Connect to database :

There are notes in the previous article :
Click on :Django Connection method with database

Four ,Django Frame configuration

File structure :

4.1 setting To configure

Set up :ALLOWED_HOSTS = ['*'] Facilitate our local access to .
Fill in “*” It can make all web sites accessible Django Project ,
When the project is tested , You can do that .

Join in “myapp” The path of :‘mylost’ by app File name

Next we need to talk to Django Describe the path of the template file , modify HelloWorld/settings.py, modify TEMPLATES Medium DIRS by [os.path.join(BASE_DIR, ‘templates’)], As shown below :

os.path.join(BASE_DIR,'TestModel/templates'),

Database connection configuration , It's mentioned above :

STATICFILES_DIRS tell django, First of all to STATICFILES_DIRS Look for static files inside , Then to each app Of static Look in the folder .
Join in :

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)

4.2 Lord urls To configure

introduce include

url First match django In the project url file , Then match the application app Medium url file . Step by step matching .

 For example, in a project , Set to match null ' ' ——> Then it will match APP In application url.

4.3 establish app Of urls file

You can copy the of the main route urls file , Change the value inside .

5、 ... and , Native front-end page

Front end path display

5.1 Login page configuration 【 Use open source front-end projects 】

Load static file
{% load static %}
Use reverse parsing technology to introduce css Corresponding documents

<!-- Introduction framework -->
<link rel="stylesheet" type="text/css" href="{% static 'css/font-awesome.4.6.0.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/snow.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">

Introduce online jqurey, You can also put it locally

<script src="https://www.ym4j.com/jquery/jquery-1.8.2.min.js"></script>

5.2css,js,images Storage path

establish templates Folder , Put in native login and registration html file .

establish static Folder , Deposit html Needed css,js And the referenced picture files .

The front end needs to be changed a lot , In order to apply , The details depend on the actual situation .

6、 ... and Formwork layer models

Temporarily write the login and registered user database , Not perfect yet .

cd To django Under the folder .
Generate migration file

python manage.py makemigrations

Perform the migration

python manage.py migrate

function

python manage.py runserver

Refer to previous articles :
Website Development Notes ——(django Introduction )

6.1 The migration file was generated successfully



6.2 Migration successful


Database display :

7、 ... and , Start the service

python manage.py runserver

7.1 Local access

Because the main page doesn't write , First look at the login registration page ;

Successfully enabled

8、 ... and , Results display


END

Gou huaisifangzhi , Where you can swim , Let's make progress together !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved