Найти - Пользователи
Полная версия: Bottle: не работает метод POST
Начало » Web » Bottle: не работает метод POST
1
Master_Sergius
Ишел по туториалу: http://bottlepy.org/docs/dev/tutorial_app.html
Заюзал get и post, как там, но ошибка - 405, method is not allowed. Почему? Как исправить?
Проблема там, где декораторы get и post, get - работает.

import os
 
# setup global and environ variables
app_root = os.path.dirname(os.path.abspath(__name__))
os.environ['FAMILY_BUDGET_ROOT'] = app_root
 
from bottle import route, run, redirect, request, get, post, static_file
from controller import check_login, get_page
 
 
# static section
 
@route('/<filename:re:.*\.css>')
def stylesheets(filename):
    return static_file(filename, root=app_root)
 
# dynamic section
 
@route('<path:path>')
def family_budget(path):
    redirect('/family_budget/login')
 
@get('/family_budget/login')
def login():
    username = request.get_cookie("account", secret='very_secret_key')
    if username:
        redirect('/family_budget/main_page')
    else:
        login_page = get_page('templates/login_page.html')
        return login_page
 
@post('/family_budget/login')
def do_login():
    username = request.forms.get('username')
    password = request.forms.get('password')
    if check_login(username, password):
        request.set_cookie("account", username, secret='very_secret_key')
        redirect('/family_budget/main_page')
    else:
        return "<p>Login failed.</p>"
 
@route('/restricted')
def restricted_area():
    username = request.get_cookie("account", secret='very_secret_key')
    if username:
        return template("Hello {{name}}. Welcome back.", name=username)
    else:
        return "You are not logged in. Access denied."
 
run(host='0.0.0.0', port=5050)
o7412369815963
Master_Sergius
405, method is not allowed
Может возникать когда нет метода, ни post ни get, или есть post но обращение по get.

Master_Sergius
@route('<path:path>')
Примените последним, т.к. он может перехватить все последующие.

Попробуйте методом исключения - отключите все роуты кроме post, и проверьте например с пом. curl.
Master_Sergius
Я понял! Я ошибся в задании пути в form action!!!
Всё работает!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB