示例#1
0
def index():
    return response([
        '''
	<!DOCTYPE html>
		<html>
		<head>
			<script
			  src="https://code.jquery.com/jquery-3.3.1.min.js"
			  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
			  crossorigin="anonymous"></script>

		</head>
		<body>
		<input id='username' type='text' />
		<input id='password' type='password' />
		<button id='submit'>Login</button>

			<script>
			$(document).ready(function() {

				$('#submit').click(function() {

					$.ajax({
					  dataType: "json",
					  url: '/login',
					  method: 'POST',
					  contentType: 'application/json',
					  data: JSON.stringify({
						username: $('#username').val(),
						password: $('#password').val()
					  }),
					  success: function() {
						console.log('done', arguments);
						window.location = '/profile';
					  },
					  error: function(data) {
					  	alert('login error');
					  }
					});

				});
			});
			</script>

		</body>
	</html>
	'''.strip()
    ],
                    mimetype='text/html')
示例#2
0
def home(x):
    text = f'''
    <!DOCTYPE html>
    <html>
        <head>
        </head>
        <body>
            <center>
            <h1>Welcome to Module</h1>
            <h2>x is {x}</h2>
            <a href='{request.path}/protected'>protected page</a>
            <a href='module.json'>module info</a>
            <hr>
            <a href='..'>back</a>
            </center>
        </body>
    </html
    '''
    return response([text], mimetype='text/html')
示例#3
0
文件: main.py 项目: Waffles32/madness
def home(x):
    text = f'''
    <!DOCTYPE html>
    <html>
        <head>
        </head>
        <body>
            <center>
            <h1>Welcome to Madness</h1>
            <h2>x is {x}</h2>
            <a href='throw'>raise api exception</a>
            <a href='invalid-route'>404 page</a>
            <a href='relative/path'>relative path!</a>

            <hr>
            <a href='module'>module</a>

            </center>
        </body>
    </html
    '''
    return response([text], mimetype='text/html')
示例#4
0
def profile(username):
    return response(
        ['welcome back, ', username, '<br /><a href=/logout>logout</a>'],
        mimetype='text/html')
示例#5
0
文件: main.py 项目: Waffles32/madness
def crossdomain():
    return response(['from anywhere!'])
示例#6
0
文件: main.py 项目: Waffles32/madness
def mypath():
    return response(['wow!!'])
示例#7
0
文件: main.py 项目: Waffles32/madness
def my404():
    return response(['not found!!'])
示例#8
0
文件: json.py 项目: Waffles32/madness
def response(obj, **kwargs):
    return madness.response(
        [json.dumps(obj)],
        mimetype = 'application/json; charset=utf-8',
        **kwargs
    )
示例#9
0
def greet(username):
    return response([f'welcome back, {username}'])