为什么此烧瓶页面无法呈现并显示500错误?

时间:2019-11-02 21:48:02

标签: flask-sqlalchemy

我对Flask和SQLAlchemy比较陌生,但我们一直在训练营学习它们。我以为我可以尝试与他们一起创建网站,但是有困难。其他页面运行正常,并且该页面在本地测试机上也可以运行,但是是否弹出500错误?我认为它可能在app.config ['SQLALCHEMY_DATABASE_URI']中,但是很难找到一个很好的解释。任何帮助,不胜感激!

from flask import Flask, request, redirect, render_template, flash, session, url_for
import cgi
import os
import math
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:password@/31.220.50.227:3306'
app.config['SQLALCHEMY_ECHO'] = True
db = SQLAlchemy(app)
app.secret_key = 'y337kGcys&zP3B'

class Catalog(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    img_location = db.Column(db.String(120))
    pdf_location = db.Column(db.String(120))
    title = db.Column(db.String(120))


    def __init__(self, img_location, pdf_location, title):
        self.img_location = img_location
        self.pdf_location = pdf_location
        self.title = title



@app.route('/')
def index():
    return render_template('index.html')

@app.route('/catalogs')
def catalogs():
    page = request.args.get('page', 1, type=int)

    catalogs = Catalog.query.paginate(page=page,per_page= 5)
    next_url = url_for('catalogs', page=catalogs.next_num) \
        if catalogs.has_next else None
    prev_url = url_for('catalogs', page=catalogs.prev_num) \
        if catalogs.has_prev else None
    img_location = request.args.get("img_location")
    down_location = request.args.get("down_location")
    return render_template('catalogs.html',title="Camera Eccentric", catalogs=catalogs, next_url=next_url, prev_url=prev_url)
{% extends "base.html" %}

{% block content %}
<div class="catalogs">
    <div class="container-fluid">
        <div class="row">
            {% for catalog in catalogs.items %}
            <div class="col-sm text-center">
                <a href="{{catalog.pdf_location}}"><img class="img-fluid" src="{{catalog.img_location}}">
                <h3>{{catalog.title}}</h3></a>
            </div>
            {% endfor %}
        </div>
    </div>
    <hr>
    <div class="container-fluid">
        <div class="row">
                <div class="col-sm text-center">  
                    {% if prev_url %}
                    <a href="{{ prev_url }}"><h3>Previous</h3></a>
                    {% endif %}
                </div>
                <div class="col-sm text-center">
                    {% for page_num in catalogs.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %}
                    {% if page_num %}
                    {% if catalogs.page == page_num %}
                    <a class="btn btn-custom mb-4" href="{{ url_for('catalogs', page=page_num) }}">{{ page_num }}</a>
                    {% else %}
                    <a class="btn btn-outline-custom mb-4" href="{{ url_for('catalogs', page=page_num) }}">{{ page_num }}</a>
                    {% endif %}
                    {% else %}
                    ...
                    {% endif %}
                    {% endfor %}
                </div>
                <div class="col-sm text-center">
                    {% if next_url %}
                    <a href="{{ next_url }}"><h3>Next</h3></a>
                    {% endif %}
                </div> 
                <div class="row mx-0">
                    <div class="col-12 bg-light text-dark">

                        <p>Researching classic cameras and lenses can be a daunting process.
                            We hope these pages will not only inform photographers about vintage camera equipment,
                            but inspire others to start using them in their future photographic and creative endeavors.
                        </p>
                        <p>We will continue to update this page with photographs, experiences, and catalogs.
                            We hope you find these helpful and greatly appreciate any contributions from other
                            photographers : )
                        </p>
                </div>
        </div>
    </div>
</div>
{% endblock %}

1 个答案:

答案 0 :(得分:0)

我知道了!好像两个烧瓶一样,sqlalchemy连接到具有小写名称的表,而我有一个具有大写名称的表。将名称更改为小写,页面即可正常工作!