Перенесено из репозитария SpecialistOff.NET
This commit is contained in:
51
myapp/views.py
Normal file
51
myapp/views.py
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
__author__ = 'RemiZOffAlex'
|
||||
__copyright__ = '(c) RemiZOffAlex'
|
||||
__license__ = 'MIT'
|
||||
__email__ = 'remizoffalex@mail.ru'
|
||||
|
||||
from myapp import app
|
||||
from flask import Flask, render_template, request
|
||||
|
||||
from . import forms, models
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
pagedata = {}
|
||||
pagedata['title'] = app.config['TITLE']
|
||||
pagedata['info'] = 'Привет мир!'
|
||||
body = render_template('index.html', pagedata=pagedata)
|
||||
return body
|
||||
|
||||
|
||||
@app.route('/edit', methods=['GET', 'POST'])
|
||||
def edit():
|
||||
pagedata = {}
|
||||
pagedata['title'] = app.config['TITLE']
|
||||
pagedata['form'] = forms.PageEdit(
|
||||
request.form,
|
||||
data={
|
||||
'title': 'Заголовок страницы',
|
||||
'text': '''<p>Текст</p>
|
||||
<p class="alert alert-danger">Внимание!</p>'''
|
||||
}
|
||||
)
|
||||
if request.method == 'POST':
|
||||
if pagedata['form'].validate():
|
||||
pagedata['title'] = pagedata['form'].title.data
|
||||
pagedata['text'] = pagedata['form'].text.data
|
||||
body = render_template('page.html', pagedata=pagedata)
|
||||
return body
|
||||
body = render_template('edit.html', pagedata=pagedata)
|
||||
return body
|
||||
|
||||
|
||||
@app.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
pagedata = {}
|
||||
pagedata['form'] = forms.LoginForm(request.form)
|
||||
body = render_template('login.html', pagedata=pagedata)
|
||||
return body
|
||||
Reference in New Issue
Block a user