# coding:utf8
# __author: Administrator
# date: 2018/3/6 0006
# /usr/bin/env python import tornado.ioloop
import tornado.web
import uimethod as mt
import uimodule as md name_list=[] # User information
USER_INFO={'login_status':None,'name':None}
# The article lists
NEWS_LIST=[
{"title":"dfwafaw","content":" It's all letters "}
] # The original test template
class MainHandler(tornado.web.RequestHandler):
def get(self):
# self.write("Hello World")
# Default to the current path
# print(self.get_argument('name'))
# print(self.get_argument('age'))
self.render("s1.html",ccc=name_list,nm="mmp") def post(self, *args, **kwargs):
name=self.get_argument('xxx')
name_list.append(name)
self.render("s1.html",ccc=name_list) # Show home page
class HomeHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html',user_status=USER_INFO['login_status'],user_name=USER_INFO['name'],content=NEWS_LIST)
# It can also be a dictionary , Use in template by Dictionary # Handle login and logout
class LoginHandler(tornado.web.RequestHandler):
def post(self, *args, **kwargs):
name=self.get_argument('username',None)
pawd=self.get_argument('password',None)# Unable to get when set to None, Prevent mistakes
if name == "ld" and pawd == '':
USER_INFO['login_status']=True
USER_INFO['name']=name
self.redirect('/home') def get(self, *args, **kwargs):
status=self.get_argument('quit')
if status == 'true':
USER_INFO['login_status']=False
USER_INFO['name']=None
self.redirect('/home') # Article release
class AddNewsHandler(tornado.web.RequestHandler):
def post(self, *args, **kwargs):
title=self.get_argument('title',None)
content=self.get_argument('content',None)
if title and USER_INFO['login_status']:
NEWS_LIST.append({"title":title,"content":content})
# Make a jump
self.redirect('home')# It's the jump method , It's not a page st ={
"template_path": "template",# Template path configuration
"static_path":'static', #js css Static file path configuration No matter what path is configured here , It is used in static files static
"static_url_path":'/ss/', # stay static_path Must exist on the basis of It's like giving it an alias
# If it were not so static_url_prefix, Then the resource in the static file is obtained as static/s1.css
# When it exists static_url_prefix when ,( The premise already exists static_path), At this time, the specific path program has obtained , You just need to prefix the resource with this , You don't need to write your own details url
# It can be seen as static_path It's a nickname
#static_url_prefix Understanding can , Not commonly used
'ui_methods':mt, # Using custom functions in templates {{}}
'ui_modules':md, # Custom classes are used in templates {% %}
} # Route mapping Match execution , otherwise 404
application = tornado.web.Application([
(r"/index",MainHandler),
(r"/home",HomeHandler),
(r"/login",LoginHandler),
(r"/addNews",AddNewsHandler),
],**st) if __name__=="__main__":
application.listen(8080) #io Multiplexing
tornado.ioloop.IOLoop.instance().start()

Template file

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!--<link rel="stylesheet" href="static/plugins/bootstrap3/css/bootstrap.css">-->
<!--<script src="static/js/jquery.js"></script>-->
<!--<script src="static/plugins/bootstrap3/js/bootstrap.js"></script>--> <!-- Note that if you want to use static_url Must define static_url_prex perhaps static_url_path, The two are similar -->
<link rel="stylesheet" href="{{static_url('plugins/bootstrap3/css/bootstrap.css')}}}">
<link rel="stylesheet" href="{{static_url('css/index.css')}}">
<script src='{{static_url("js/jquery.js")}}'></script >
<script src="{{static_url('plugins/bootstrap3/js/bootstrap.js')}}"></script> </head>
<body>
<div>
{% if user_status %}
<h1> Hello :{{user_name}}<a onclick="PostNews();"> Release the news </a><div style="float: right;"><a href="/login?quit=true"> sign out </a></div></h1> {% else %}
<h1> Please first <a onclick="Login();"> Sign in </a></h1>
{% end %}
</div>
<div class="content-list">
{% for item in content %}
<div class="item">
<div class="title">{{item['title']}}</div>
<div class="content">{{item['content']}}</div>
</div>
{% end %}
</div>
<div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form action="login" method="post">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="exampleModalLabel"> The user login </h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="control-label"> user name :</label>
<input type="text" class="form-control" name="username">
</div>
<div class="form-group">
<label class="control-label"> password :</label>
<input type="password" class="form-control" name="password">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div> <div class="modal fade" id="pub" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form action="addNews" method="post">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="exampleModalLabel"> The user login </h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="control-label"> title :</label>
<input type="text" class="form-control" name="title">
</div>
<div class="form-group">
<label class="control-label"> Content :</label>
<textarea class="form-control" name="content" id="message-text"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<script>
function Login(){
$("#login").modal('show');
} function PostNews(){
$("#pub").modal('show');
}
</script>

python---tornado First time to know (2) Login and publish more related articles

  1. tornado web Advanced development project drawer official website page login verification 、form verification 、 give the thumbs-up 、 Comment on 、 Pagination of articles 、 Send email verification code 、 Login verification code 、 register 、 Publish articles 、 To upload pictures

    This blog will lead you step by step to realize the various functions of the drawer official website : Including landing . register . Send email verification code . Login verification code . Page login verification . Publish articles . To upload pictures .form verification . give the thumbs-up . Comment on . Article pagination processing and based on tornado The back end and ajax Of ...

  2. python tornado websocket More chat rooms ( Return the message to part of the connector )

    python tornado Build multiple chat rooms , Multiple chat rooms are independent of each other , Realize that the server will return the message to the corresponding part of the client ! chatHome.py // Server side , Render the home page --> Chat room set up web ...

  3. Python Tornado brief introduction

    brief introduction Tornado  yes  FriendFeed  The extensible non blocking web Open source versions of servers and related tools . This Web The frame looks a bit like web.py  perhaps  Google Of webapp, But for ...

  4. Python + Selenium Automatically publish articles ( One ): Open source in China

    https://blog.csdn.net/qq_28804275/article/details/80891949 https://blog.csdn.net/qq_28804275/article ...

  5. python Reptiles scrapy frame —— Manual identification of the login depends on the inverted character verification code and digital English verification code (2)

    Operating environment :python3 In the last article python Reptiles scrapy frame -- Manual identification of Zhihu login Zhihu inverted text verification code and digital English verification code (1) We've talked about using Requests Library to log in , If you don't understand this article, you can read it first ...

  6. Python.tornado.0

    Tornado https://github.com/facebook/tornado http://www.tornadoweb.org/en/stable/guide/intro.html  (A ...

  7. Python I'm new to notes

    Python I'm new to notes

  8. utilize python Next paramiko Module login without password

    utilize python Next paramiko Module login without password   Last time I introduced the use of paramiko This module , Can simulate ssh Log in to the remote server , And can return the result of the executed command , This time I'll show you how to use the established key ...

  9. Lonely lotus Ling Han taught himself python On day 67, I had a preliminary understanding of Python Reptiles are new requests modular

    Lonely lotus Ling Han taught himself python On day 67, I had a preliminary understanding of Python Reptiles are new requests modular ( The complete learning process screen records the video address at the end of the article ) From today on, we will begin to study formally Python The reptiles of . Today, I have a preliminary understanding of the two main modules : ...

Random recommendation

  1. Android in NDK It's easy to build and use Android.mk Related introduction JNI Use

    Android in NDK It's easy to build and use : Use NDK, Briefly describe its important steps :. build NDK Environmental Science ( effect : Used to automatically generate jni Under the .c Corresponding so file )--- To Android NDK Official website or Android Download from the official website ndk ...

  2. iOS Picture loading new frame - FlyImage

    FlyImage  Integrated SDWebImage,FastImageCache,AFNetworking The advantages of , It's a new performance efficient . Interface simple picture loading framework . characteristic Efficient Multiple small pictures can be decoded and stored in the same large picture ...

  3. class Use

    class test(object): """ get It's called test Object method """ def __init__(self,var1): ...

  4. android in PreferenceScreen The use of the class

    PreferenceScreen preference It's a preference , First choice means ,PreferenceScreen Personal translation into “ Preference display ”, Just understand that , That is to say, according to the characteristics of flexible definition of display content style , One screen can ...

  5. H3C Switch 802.1&amp;dot1x authentication

    1. Global activation Dot1x Authentication function [H3C]dot1x 2. Enter the interface activation dot1x [H3C]interface GigabitEthernet 1/0/1 [H3C-GigabitEthernet1/ ...

  6. TensorFlow Fitting a linear function

    TensorFlow Fitting a linear function ordinary TensorFlow Graph construction Take a single neuron x_data The data is 20 A random [0, 1) Of 32 Bit floating-point number according to shape=[20] The tensor of composition y_data by ...

  7. webservice Generate client code

    wsimport -d C:\Other\WSDL_JAVA_Code -keep -verbose -Xauthfile C:\Other\.txt http://XXXXXX

  8. Android studio android studio After Sinicization , Report errors . The setup interface doesn't open .Can&#39;t find resource for bundle java.util.PropertyResourceBundle, key emmet.bem.class.name.element.separator.label

    Android studio  android studio After Sinicization , Report errors . The setup interface doesn't open . Android studio has been sinified and reported wrong.The setup ...

  9. git The solution to the problem of multi account switching in ( turn )

    author : Know the user link :https://www.zhihu.com/question/23028445/answer/416231632 source : It's up to the author to own the copyright . Commercial reprint please contact the author for authorization , Non commercial reprint please ...

  10. Linux Next use Nexus build Maven Private clothes

    In the development process , Sometimes we use some development packages inside the company , Obviously it's not appropriate to put these bags on the outside . in addition , Because the project has been under development , These internal dependencies may also be constantly updated . It can be done by building the internal Maven The server , The third party and the internal ...