ops_render替换解决current_user

来源:7-5 编辑和修改登录人信息

weixin_慕慕5408511

2020-12-10

from common.libs.user.Helper import ops_render
from common.models.User import ( User ) #利用orm来读取
from common.libs.user.UserService import (UserService )
from common.libs.UrlManager import (UrlManager )
from application import db,app
import json

route_user = Blueprint( ‘user_page’,name )

@route_user.route( “/login”,methods = [ “GET”,“POST” ])
def login():
if request.method==“GET”:
return render_template( “user/login.html” )
resp = {‘code’: 200, ‘msg’: ‘登录成功~~’, ‘data’: {}} #定义一个字典
req=request.values #字典 return req[‘login_pwd’]
login_name=req[‘login_name’] if ‘login_name’ in req else ''
问题 其他替换解决current_user没有问题。但是如果用login这边替换会不会死循环。??

写回答

5回答

编程浪子

2020-12-14

你好

兄弟你看你加我qq:1586538192  ,我给你看看,这样沟通还是不太清楚

0
2
编程浪子
回复
weixin_慕慕5408511
CodeRonin666
2020-12-15
共2条回复

weixin_慕慕5408511

提问者

2020-12-11

@route_user.route( "/login",methods = [ "GET","POST" ])
def login():
   if request.method=="GET":
       if g.current_user:
           return redirect(UrlManager.buildUrl("/"))
       return render_template( "user/login.html" )
   resp = {'code': 200, 'msg': '登录成功~~', 'data': {}}  #定义一个字典
   req=request.values  #字典  return req['login_pwd']
   login_name=req['login_name']  if 'login_name' in req else ''
   login_pwd=req['login_pwd'] if 'login_pwd' in req else ''#条件语句简化写法
   #输入有效性判断
   if login_name is None or len(login_name)<1:
       resp['code'] = -1
       resp['msg'] = "请输入正确的用户账号~~"
       return jsonify(resp)
   if login_pwd is None or len(login_pwd) < 1:
       resp['code'] = -2
       resp['msg'] = "请输入正确的用户密码~~"
       return jsonify(resp)
   user_info = User.query.filter_by(login_name=login_name).first()#从数据库按login_name读取记录--行
   if not user_info:
       resp['code'] = -3
       resp['msg'] = "请输入正确的登录用户名和密码-1~~"
       return jsonify(resp)

   if user_info.login_pwd != UserService.genePwd( login_pwd,user_info.login_salt ):
       resp['code'] = -3
       resp['msg'] = "请输入正确的登录用户名和密码-2~~"
       return jsonify(resp)

   if user_info.status != 1:
       resp['code'] = -4
       resp['msg'] = "账号已被禁用,请联系管理员处理~~"
       return jsonify(resp)
   response=make_response(json.dumps({'code': 200, 'msg': '登录成功~~'}))
   response.set_cookie(app.config['AUTH_COOKIE_NAME'], '%s#%s' % (
       UserService.geneAuthCode(user_info), user_info.uid), 60 * 60 * 24 * 120)  # 保存120天

   return response

0
0

编程浪子

2020-12-10

你好

根据你的代码和错误

TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.


我看你好像是没有返回值的,所以报错很正常了

//img.mukewang.com/szimg/5fd1d536090b8c5f23381046.jpg


这里有源码:https://git.imooc.com/coding-265/coding-265/src/master/%e5%ae%8c%e6%95%b4%e6%ba%90%e7%a0%81/web/controllers/user/User.py 

0
1
weixin_慕慕5408511
有return
2020-12-11
共1条回复

weixin_慕慕5408511

提问者

2020-12-10

from flask import Blueprint,request,jsonify,redirect,make_response

from common.libs.user.Helper import ops_render
from common.models.User import ( User )   #利用orm来读取
from common.libs.user.UserService import (UserService )
from common.libs.UrlManager import  (UrlManager )
from application import db,app
import json

route_user = Blueprint( 'user_page',__name__ )

@route_user.route( "/login",methods = [ "GET","POST" ])
def login():
   if request.method=="GET":
       return ops_render( "user/login.html" )
   resp = {'code': 200, 'msg': '登录成功~~', 'data': {}}  #定义一个字典
   req=request.values  #字典  return req['login_pwd']
   login_name=req['login_name']  if 'login_name' in req else ''
   login_pwd=req['login_pwd'] if 'login_pwd' in req else ''



报错:

ent: production

   WARNING: This is a development server. Do not use it in a production deployment.

   Use a production WSGI server instead.

 * Debug mode: on

 * Restarting with stat

 * Debugger is active!

 * Debugger PIN: 303-038-651

 * Running on http://0.0.0.0:5999/ (Press CTRL+C to quit)

20.148.5.124 - - [10/Dec/2020 15:07:57] "?[35m?[1mGET /user/login HTTP/1.1?[0m" 500 -

Traceback (most recent call last):

  File "C:\Users\lenovo\PycharmProjects\lab12\venv\Lib\site-packages\flask\app.py", line 2463, in __call__

    return self.wsgi_app(environ, start_response)

  File "C:\Users\lenovo\PycharmProjects\lab12\venv\Lib\site-packages\flask\app.py", line 2449, in wsgi_app

    response = self.handle_exception(e)

  File "C:\Users\lenovo\PycharmProjects\lab12\venv\Lib\site-packages\flask\app.py", line 1866, in handle_exception

    reraise(exc_type, exc_value, tb)

  File "C:\Users\lenovo\PycharmProjects\lab12\venv\Lib\site-packages\flask\_compat.py", line 39, in reraise

    raise value

  File "C:\Users\lenovo\PycharmProjects\lab12\venv\Lib\site-packages\flask\app.py", line 2446, in wsgi_app

    response = self.full_dispatch_request()

  File "C:\Users\lenovo\PycharmProjects\lab12\venv\Lib\site-packages\flask\app.py", line 1952, in full_dispatch_request

    return self.finalize_request(rv)

  File "C:\Users\lenovo\PycharmProjects\lab12\venv\Lib\site-packages\flask\app.py", line 1967, in finalize_request

    response = self.make_response(rv)

  File "C:\Users\lenovo\PycharmProjects\lab12\venv\Lib\site-packages\flask\app.py", line 2096, in make_response

    raise TypeError(

TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.





0
0

编程浪子

2020-12-10

你好

我还是没有太明白你的意思。麻烦你在解释下。

0
1
weixin_慕慕5408511
就是会报错
2020-12-10
共1条回复

Python Flask构建微信小程序订餐系统(可用于毕设)

微信小程序 + Python Flask 打造订餐系统全栈应用,可用于毕设。

1709 学习 · 1904 问题

查看课程