@y_w_y_w

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

【End of script output before headers: index.cgi】のエラーを解消したい

解決したいこと

【End of script output before headers: index.cgi】のエラーを解消したい

例)
FlaskでWEBアプリの製作を始めた初心者です。
レンタルサーバー上にミニコンダにて、Pythonの環境を整えました。
こちらを参考にしました
https://dattesar.com/xserver-pip-flask/

・・・・コードはここから・・・・・・・・・・
from flask import Flask

app = Flask(name)

#1
@app.route('/')
def hello_world():
return 'Hello, World!'

#2
@app.route("/main", methods=["GET", "POST"])
def main_page():
return render_templates("mainpage.html")

・・・ここまで・・・・・・・・・・・・・・・・・・

#1をブラウザにURLを直接入力すると、エラーにならず、ハローワールドと言ってくれます。
#2をブラウザにURLを直接入力すると、【Internal Server Error】となってしまいます

.htaccessはこうなっています
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /flask-test/index.cgi/$1 [QSA,L]

index.cgiはこうなっています
#! /home/wtsx0001/miniconda3/envs/flaskapp/bin/python
print("Content-Type: text/html\n\n")
from wsgiref.handlers import CGIHandler
from helloFlask import app
CGIHandler().run(app)

pyファイルはこうなっています
from flask import Flask

app = Flask(name)

@app.route('/')
def hello_world():
return 'Hello, World!'

@app.route("/main", methods=["GET", "POST"])
def main_page():
return render_templates("mainpage.html")

自分で試したこと

・エラーログの確認
[Sat Apr 15 15:32:53.182656 2023] [cgid:error] [pid 63184:tid 63694] [client 153.231.9.231:50954] End of script output before headers: index.cgi

との事でしたので、ヘッダーが終了する前にスクリプトが終わってしまった、という意味と思いましたので、それを中心に過去記事の検索⇒訂正⇒作り直し・・・・
3日程経ってしまいましたので、投稿させて頂きます。

初歩的な所で恐縮ですが、ご教授、お願い致します。

0 likes

1Answer

Comments

  1. methods=["GET"...のPOSTの意味は何でしょうね?

    from flask import Flask, render_template
    
    app = Flask(?__name__?)
    @app.route("/main")
    def main_page():
       return render_template?s?("mainpage.html")
    

    尚、サンプルは正しくコピぺするか?
    スペルは正しく記入しましょう?

    ```
    次回からコードは半角```で括りましょう!
    ```

Your answer might help someone💌