Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
96 views
in Technique[技术] by (71.8m points)

python - I am haveing some issues with a post method, i am getting {"detail":"Method Not Allowed"}

I am new to developing in general and I am trying to figure out why i keep getting {"detail":"Method Not Allowed"} here is a snipit of what i have. I am printing the http variables on the site so I know i am getting correct values. in this case strategy.id == 1 and stock.id == 1 I have checked the sql statement by manually running it in a sql viewer as INSERT INTO stock_strategy (stock_id, strategy_id) VALUES (1, 1) and that works as well. I am sure i am just missing a comma or some other little thing, but i cannot for the life of me find it.

    <form method="post">
        <select name="strategy_id">
            {% for strategy in strategys %}
            <option value="{{ strategy.id }}">{{ strategy.name }}</option>
            {% endfor %}
        </select>
        <input type="text" name="stock_id" value="{{ stock.id }}" />
        <input type="submit" value="Apply strategy" />
    </form>



@app.post("/apply_strategy")
def apply_strategy(strategy_id: int = Form(...), stock_id: int = Form(...)):    
    connection = sqlite3.connect(config.db_path)
    cursor = connection.cursor()

    cursor.execute("""
        INSERT INTO stock_strategy (stock_id, strategy_id) VALUES (?, ?)
    """, (stock_id, strategy_id))

    connection.commit()

    return RedirectResponse(url=f"/strategy/{strategy_id}", status_code=303)
question from:https://stackoverflow.com/questions/65905321/i-am-haveing-some-issues-with-a-post-method-i-am-getting-detailmethod-not

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...