资源简介
python 编写,前端完整,前后端分离方案
方案一
本地服务器在家 外面不能连接家里网络的 因为 家里不需要开放某些端口,那么 本地服务器: 运行爬虫 + 本地网站 远程服务器: sphinx 索引+ mysql + nginx + gunicorn + 网站
方案二
两台都是买的外面的服务器的话, 分别为A 和 B 。 A做为前端: 网站 B作为服务器: 爬虫+ sphinx索引 + mysql + gunicorn 服务
代码片段和文件信息
#encoding:utf-8
#我本戏子2017.7
import sys
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
import redis
import re
import base64
import json
import codecs
import time
import os
import datetime
from flask import Flaskrequestrender_templatesessiongurl_forredirectflashcurrent_appjsonifysend_from_directory
from flask_login import LoginManagerUserMixincurrent_userlogin_requiredlogin_userlogout_user
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Date cast func
from flask_script import Manager Shell
from flask_migrate import Migrate MigrateCommand
from flask_wtf import FlaskForm
from wtforms import StringFieldPasswordFieldSubmitFieldBooleanFieldTextField
from wtforms.validators import DataRequiredLengthEqualToValidationerror
from flask_babelex import Babelgettext
from flask_admin import helpers AdminIndexView Admin baseView expose
from flask_admin.contrib.sqla import ModelView
from flask_admin.contrib.fileadmin import FileAdmin
from flask_admin.form.upload import ImageUploadField
from getpass import getpass
from flask_caching import Cache
from werkzeug.security import generate_password_hashcheck_password_hash
import jieba
import jieba.analyse
import pymysql
#from flask_debugtoolbar import DebugToolbarExtension
file_path = os.path.join(os.path.dirname(__file__) ‘uploads‘)
# Initialize Flask and set some config values
app = Flask(__name__)
app.config[‘DEBUG‘]=True
app.config[‘SECRET_KEY‘] = ‘super-secret‘
#debug_toolbar=DebugToolbarExtension()
#debug_toolbar.init_app(app)
#app.config[‘DEBUG_TB_INTERCEPT_REDIRECTS‘]=False
app.config[‘SQLALCHEMY_DATAbase_URI‘] = ‘mysql+pymysql://root:123456@127.0.0.1:3306/zsky‘
app.config[‘SQLALCHEMY_TRACK_MODIFICATIONS‘] = True
app.config[‘SQLALCHEMY_POOL_SIZE‘]=5000
db = SQLAlchemy(app)
manager = Manager(app)
migrate = Migrate(app db)
babel = Babel(app)
app.config[‘BABEL_DEFAULT_LOCALE‘] = ‘zh_CN‘
loginmanager=LoginManager()
loginmanager.init_app(app)
loginmanager.session_protection=‘strong‘
loginmanager.login_view=‘login‘
loginmanager.login_message = “请先登录!“
cache = Cache(appconfig = {
‘CACHE_TYPE‘: ‘redis‘
‘CACHE_REDIS_HOST‘: ‘127.0.0.1‘
‘CACHE_REDIS_PORT‘: 6379
‘CACHE_REDIS_DB‘: ‘‘
‘CACHE_REDIS_PASSWORD‘: ‘‘
})
cache.init_app(app)
DB_HOST=‘127.0.0.1‘
DB_NAME_MYSQL=‘zsky‘
DB_PORT_MYSQL=3306
DB_NAME_SPHINX=‘film‘
DB_PORT_SPHINX=9306
DB_USER=‘root‘
DB_PASS=‘123456‘
DB_CHARSET=‘utf8mb4‘
sitename=“BtGoogle“
#站点名
domain=“http://www.btgoogle.net“
#sitemap里的域名
class LoginForm(FlaskForm):
name=StringField(‘用户名‘validators=[DataRequired()Length(132)])
password=PasswordField(‘密码‘validators=[DataRequired()Length(120)])
def get_user(self):
return db.session.query(User).filter_by(name=self.name.data).first()
class SearchForm(FlaskForm):
search = StringField(validators = [DataRequired(message= ‘请输入关键字‘)]render_kw={“placeholder“:“搜索电影软件图片资料番号....“})
submit = SubmitField(‘搜索‘)
class Search_Filelist(db.Model):
“““ 文件列表 “
- 上一篇:splitAtlasEx.py
- 下一篇:python学习数据集集合
评论
共有 条评论