Python,Flaskを用いたプログラム
上記の通り、Lolipopでブログのようなプログラムを動かしたいのですが、
Internal Server Errorが出てしまいます。
最小限のコードでは動きましたが、オリジナルの物をアップロードするとエラーになってしまいます
解決策を提示していただけると幸いです。
エラーメッセージ
Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at https://lolipop.jp/support/ to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
該当のソースコード(すべて貼っておきます)
python
1#views.py 2from typing import Text 3from flask import Flask,request,redirect,url_for,render_template,flash,session 4from sqlalchemy.sql.functions import user 5from models.entries import Entry ,SESSION,User 6from sqlalchemy.engine import base 7from sqlalchemy import text 8from datetime import datetime 9 10app = Flask(__name__) 11app.config['DEBUG'] = True 12app.config['USERNAME'] = 'admin' 13app.config['PASSWORD'] = 'admin' 14app.config['SECRET_KEY'] = 'gmowyu7938q2y7uhfsiu7827rngw7390167reidnsdhgoi2yifg6t783hj4i' 15 16@app.route('/') 17def show_entries(): 18 if not session.get('logged_in'): 19 return redirect(url_for('login')) 20 entrie = SESSION.query(Entry).all() 21 usernames = session.get('username') 22 return render_template('home.html',entries = entrie,usernames = usernames) 23@app.route('/signup', methods=['GET', 'POST']) 24def signup(): 25 if request.method == 'POST': 26 userm = User( 27 name = request.form['usernames'], 28 password = request.form['passwords'], 29 ) 30 SESSION.add(userm) 31 SESSION.commit() 32 flash('signuped') 33 return redirect(url_for('login')) 34 elif request.method == 'GET': 35 return render_template('signups.html') 36 else: 37 pass 38@app.route('/login',methods=['GET','POST']) 39def login(): 40 if request.method == 'POST': 41 pname = request.form['username'] 42 p1 = SESSION.query(User).filter(text("name=:name")).params(name=pname)#.first() 43 44 for row in p1: 45 NAME = row.name 46 PASSWD = row.password 47 if request.form['username'] != NAME: 48 flash('error:username') 49 elif request.form['password'] != PASSWD: 50 flash('error:passwd') 51 else: 52 session['logged_in']=True 53 session['username']=NAME 54 flash('logged_in') 55 return redirect(url_for('show_entries')) 56 return render_template('login.html') 57@app.route('/logout') 58def logout(): 59 session.pop('logged_in',None) 60 session.pop('username',None) 61 flash('logged out') 62 return redirect(url_for('show_entries')) 63@app.route('/entries',methods=['POST']) 64def add_entry(): 65 if not session.get('logged_in'): 66 return redirect(url_for('login')) 67 entry = Entry( 68 long = request.form['long'], 69 subject = request.form['subject'], 70 comment = request.form['comment'], 71 created_at = datetime.utcnow() 72 ) 73 SESSION.add(entry) 74 SESSION.commit() 75 flash('created') 76 return redirect(url_for('show_entries')) 77@app.route('/entries/new') 78def new_entry(): 79 if not session.get('logged_in'): 80 return redirect(url_for('login')) 81 return render_template('new.html')
python
1#entries.py 2from sqlalchemy.sql.sqltypes import DateTime, Time 3from sqlalchemy import create_engine 4from sqlalchemy.ext.declarative import declarative_base 5from sqlalchemy import Column, Integer, String 6from sqlalchemy.orm import sessionmaker 7 8engine = create_engine('sqlite:///coco.db', echo=True , connect_args={'check_same_thread': False}) #, timeout=10, uri=True , check_same_thread=True 9Base = declarative_base() 10class Entry(Base): 11 __tablename__ = 'entries' 12 id = Column(Integer,primary_key=True) 13 long = Column(String(10)) 14 subject = Column(String(50)) 15 comment = Column(String(50)) 16 created_at = Column(DateTime) 17 class User(Base): 18 __tablename__ = 'user' 19 id = Column(Integer, primary_key=True) 20 name = Column(String) 21 password = Column(String) 22 roll = Column(String) 23 Session = sessionmaker(bind=engine) 24SESSION = Session() 25Base.metadata.create_all(engine) 26userdata = User( 27 name = "admin", 28 password = "admin", 29 roll = True 30) 31SESSION.add(userdata) 32SESSION.commit()
python
1#config.py 2DEBUG=True 3USERNAME='admin' 4PASSWORD='admin' 5SECRET_KEY = 'f47wyhdfa8387hadfja3798293uhda83jk' 6SQLALCHEMY_DATABASE_URI = 'sqlite:///coco.db' 7SQLALCHEMY_TRACK_MODIFICATIONS = True
python
1#!/usr/local/bin/python3.7 2#index.cgi 3from wsgiref.handlers import CGIHandler 4from views import app 5CGIHandler().run(app)
#.htaccess RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /ffftp/index.cgi/$1 [QSA,L]
html
1<!--home.html--> 2{% extends "layout.html" %} 3{% block content %} 4<ul class="list-group list-group-flush"> 5 {% for entry in entries %} 6 <div class="card"> 7 <div class="card-body"> 8 <h5 class="card-title">{{ entry.id }}:{{ usernames }}さんが、{{ entry.subject }}を{{ entry.long }}分学習しました!</h5><!--{{ usernames }}さんが、--> 9 <h6>一言:{{ entry.comment }}</h6> 10 <h7>created-at:{{ entry.created_at }}</h7> 11 </div> 12 </div> 13 {% else %} 14 noarticle 15 {% endfor %} 16</ul> 17{% endblock %}
html
1<!--layout.html--> 2<!DOCTYPE html> 3<title>coco study</title> 4<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> 5<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> 6<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script> 7<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> 8<div class="container"> 9 <nav class="navbar navbar-expand-lg navbar-light bg-light"> 10 <a class="navbar-brand" href="{{url_for('show_entries')}}">Coco study</a> 11 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> 12 <span class="navbar-toggler-icon"></span> 13 </button> 14 <div class="collapse navbar-collapse" id="navbarNav"> 15 <ul class="nav navbar-nav navbar-right"> 16 {% if not session.logged_in %} 17 <li class="nav-item"> 18 <a class="nav-link" href="{{url_for('login')}}">login</a> 19 </li> 20 <li class="nav-item"> 21 <a class="nav-link" href="{{url_for('signup')}}">signup</a> 22 </li> 23 {% else %} 24 <li class="nav-item"> 25 <a class="nav-link" href="{{url_for('new_entry')}}">new entry</a> 26 </li> 27 <li class="nav-item"> 28 <a class="nav-link" href="{{url_for('logout')}}">logout</a> 29 </li> 30 {% endif %} 31 </ul> 32 </div> 33 </nav> 34 {% for message in get_flashed_messages() %} 35 <div class="alert alert-info" role="alert"> 36 {{ message }} 37 </div> 38 {% endfor %} 39 <div class="blog-body"> 40 {% block content %} 41 {% endblock %} 42 </div> 43</div>
html
1<!--login.html--> 2{% extends "layout.html" %} 3{% block content %} 4<form action="/login" method="POST"> 5 <div class="form-group"> 6 <label for="InputTitle">username</label> 7 <input type="text" class="form-control" id="InputTitle" name="username"> 8 </div> 9 <div class="form-group"> 10 <label for="InputPassword">password</label> 11 <input type="password" class="form-control" id="InputPassword" name="password"> 12 </div> 13 <button type="submit" class="btn btn-primary">login</button> 14</form> 15{% endblock %}
html
1<!--new.html--> 2{% extends "layout.html" %} 3{% block content %} 4<form action="{{url_for('add_entry')}}" method="POST" class="add-entry"> 5 <div class="form-group"> 6 <label for="InputSubject">Subject</label> 7 <input type="text" class="form-control" id="InputSubject" name="subject"> 8 </div> 9 <div class="form-group"> 10 <label for="Inputlong">long</label> 11 <input type="text" class="form-control" id="Inputlong" name="long"> 12 <label for="Inputlong">分</label> 13 </div> 14 <div class="form-group"> 15 <label for="inputcomment">comment</label> 16 <input type="text" class="form-control" id="Inputcomment" name="comment"> 17 </div> 18 <button type="submit" class="btn btn-primary">create</button> 19</form> 20{% endblock %}
html
1<!--signups.html--> 2{% extends "layout.html" %} 3{% block content %} 4<form action="/signup" method="POST"> 5 <div class="form-group"> 6 <label for="Inputname">username</label> 7 <input type="text" class="form-control" id="Inputname" name="usernames"> 8 </div> 9 <div class="form-group"> 10 <label for="InputPassword">password</label> 11 <input type="password" class="form-control" id="InputPassword" name="passwords"> 12 </div> 13 <button type="submit" class="btn btn-primary">signup</button> 14</form> 15{% endblock %}
試したこと
lolipopのパス、パーミッション、htaccess、index.cgiの修正
補足情報
ディレクトリ構造
/| |-/models |-__init__.py(空) |-entries.py |-/templates |-home.html |-layout.html |-login.html |-new.html |-signups.html |-.htaccess |-__init__.py(空) |-coco.db |-config.py |-index.cgi |-views.py
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。