使用Python+Flask开发博客项目,并实现内网穿透

前言

Flask是一个使用python编写的轻量级Web框架,对比其他相同类型的框架而言,这个框架更加的灵活轻便。并且具有很强的定制性,用户可以根据自己的需求添加功能,有强大的插件库,这也是为什么这个框架在python领域一直火热的原因。这篇文章我们将使用这个框架编写一个属于自己的博客网站!并教你如何通过使用内网穿透工具处理项目,让本地的项目可以在公网访问!

文章目录

    • 1.个人的注册与登录模块
    • 2.首页文章展示模块
    • 3.文章详情展示模块
    • 4.文章发布模块
    • 5.文章添加分类模块
    • 6.文章分类管理模块
    • 7.文章管理模块
    • 8.用户个人信息注销模块
    • 9.信息管理模块
    • 10.程序启动模块
    • 11.内网穿透模块
    • 12.总结

??首先来看看我们开发的博客Web项目的一些展示

项目主要包含主要以下功能:个人注册于登录,首页文章展示,文章详情展示,文章发布模块,文章添加分类模块,文章分类管理模块,用户信息管理模块,程序启动模块。

??下面我们对各个模块的代码进行编写

1.个人的注册与登录模块

这个模块的主要让用户进行用户的注册,之后判断输入的密码是否一致,并将结果写入到数据库。

from flask import render_template, redirect, url_for, request, flash, session
from front_back import front
from modles.dbmodels import User, db
import hashlib
from utils import login_check


@front.route('/login',methods=['GET','POST'])
def login():
    if request.method=='GET':
        return render_template('login.html')
    elif request.method=='POST':
        username=request.form.get('username')
        password=request.form.get('password')
        user=User.query.filter_by(username=username,password=password).first()
        print(user)
        if user:
            session['user']=username
            print(session['user'])
            flash('登录成功')
            return redirect(url_for('front.index'))
        else:
            flash('登录失败')
            return redirect(url_for('front.login'))

@front.route('/register',methods=['GET','POST'])
def register():
        # 如果是get请求的话就返回页面,post请求的话就接收表单数据
        if request.method == 'GET':
            return render_template("register.html")
        elif request.method == 'POST':
            username = request.form.get('username')
            password = request.form.get('password')
            check_password = request.form.get('check_password')

            if username and password and password == check_password:
                md5 = hashlib.md5()
      

你可能感兴趣的:(面试,学习路线,阿里巴巴,flask,python,后端,java,算法)