• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

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

23.01.03 00:46 작성 조회수 148

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가 나오네요.
혹시 무엇이 문제일까요?

 

답변 0

답변을 작성해보세요.

답변을 기다리고 있는 질문이에요.
첫번째 답변을 남겨보세요!