강의

멘토링

커뮤니티

Inflearn Community Q&A

rbdid3691345's profile image
rbdid3691345

asked

Utilizing Python Flask-based web development and business automation services

Understanding the Jinja2 Template Engine - Second Practice Problem

연습문제 풀이 질문입니다.

Written on

·

270

0

구구단 출력 문제인데 질문이 있습니다.

main.py

from flask import Flask
from flask import render_template
from flask import redirect
from flask import request
from flask import url_for

app = Flask(__name__)

@app.route("/")
@app.route("/<int:num>", methods=['POST', 'GET'])
def gugudan(num=None):
    if request.method == 'GET':
        return render_template('index.html', gugudan=None)
    else:
        temp = request.form['input']
        return render_template('index.html', gugudan=temp)

if __name__ == "__main__":
    app.run(debug=True)

 

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='file.css') }}">
</head>
<body>
    <form action="/" method="POST">
        <p><input type="text"/ id="input" value="name"><input type="submit"></button></p>
    <form>

    {% if gugudan == None%}
        <p>Have to Type number</p>
    {% else %}
        <p>숫자가 입력되었습니다</p>
    {% endif %}
</body>
</html>

 

위와 같이 main.py에서 method 타입을 2가지로 나눠서 한번에 처리도 가능할거라 생각했는데, method not allowed가 나오네요.
혹시 무엇이 문제일까요?

 

문제질문mongodbflask

Answer

This question is waiting for answers
Be the first to answer!
rbdid3691345's profile image
rbdid3691345

asked

Ask a question