首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pset9 cs5中注册错误(意外异常)

pset9 cs5中注册错误(意外异常)
EN

Stack Overflow用户
提问于 2022-11-09 16:32:09
回答 1查看 25关注 0票数 -3

“注册用户成功应用程序引发异常(详细信息见日志)”注册拒绝重复的用户名应用程序引发异常(更多详细信息,请参见日志)

做些什么:(

REGISTER.HTML:

代码语言:javascript
复制
{% extends "layout.html" %}

{% block title %}
    Register
{% endblock %}

{% block main %}
    <form action="/register" method="post">
        <div class="form-group">
            <input autocomplete="off" autofocus class="form-control" name="username" placeholder="Username" type="text">
        </div>
        <div class="form-group">
            <input autocomplete="off" class="form-control" name="password" placeholder="Password" type="password" >
        </div>
        <div class="form-group">
            <input autocomplete="off" class="form-control" name="confirmation" placeholder="Password (again)" type="password">
        </div>
        <button class="btn btn-primary" type="submit">Register</button>
    </form>
{% endblock %}

INDEX.HTML:

代码语言:javascript
复制
% extends "layout.html" %}

{% block title %}
    Portfolio
{% endblock %}

{% block main %}
    <table class="table table-striped">
        <thead>
            <tr>
                <th>Symbol</th>
                <th>Name</th>
                <th>Shares</th>
                <th>Price</th>
                <th>TOTAL</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <td colspan="4"></td>
                <td>{{ sum_totals | usd }}</td>
            </tr>
        </tfoot>
        <tbody>
            {% for summary in summaries %}
                <tr>
                    <td>{{ summary.symbol }}</td>
                    <td>{{ summary.company }}</td>
                    <td>{{ summary.sum_of_shares }}</td>
                    <td>{{ summary.price | usd }}</td>
                    <td>{{ summary.total | usd }}</td>
                </tr>
            {% endfor %}
            <tr>
                <td colspan="4">CASH</td>
                <td>{{ owned_cash | usd }}</td>
            </tr>
        </tbody>
    </table>
{% endblock %}

APPY.PY (寄存器):

代码语言:javascript
复制
@app.route("/register", methods=["GET", "POST"])
def register():
    """Register user"""
    if request.method == "POST":

        if not (username := request.form.get("username")):
            return apology("MISSING USERNAME")

        if not (password := request.form.get("password")):
            return apology("MISSING PASSWORD")

        if not (confirmation := request.form.get("confirmation")):
            return apology("PASSWORD DON'T MATCH")

        # Query database for username
        rows = db.execute("SELECT * FROM users WHERE username = ?;", username)

        # Ensure username not in database
        if len(rows) != 0:
            return apology(f"The username '{username}' already exists. Please choose another name.")

        # Ensure first password and second password are matched
        if password != confirmation:
            return apology("password not matched")

        # Insert username into database
        id = db.execute("INSERT INTO users (username, hash) VALUES (?, ?);",
                        username, generate_password_hash(password))

        # Remember which user has logged in
        session["user_id"] = id

        flash("Registered!")

        return redirect("/")
    else:
        return render_template("register.html")

如果有人想看到整个文档,请写信给ambrosinogiuliana1@gmail.com。这是我最后一次能够完成这门课程的练习:

“以允许用户通过表单注册帐户的方式完成注册的实现。

代码语言:javascript
复制
Require that a user input a username, implemented as a text field whose name is username. Render an apology if the user’s input is blank or the username already exists.
Require that a user input a password, implemented as a text field whose name is password, and then that same password again, implemented as a text field whose name is confirmation. Render an apology if either input is blank or the passwords do not match.
Submit the user’s input via POST to /register.
INSERT the new user into users, storing a hash of the user’s password, not the password itself. Hash the user’s password with generate_password_hash Odds are you’ll want to create a new template (e.g., register.html) that’s quite similar to login.html.

一旦您正确地实现注册,您应该能够注册一个帐户和登录(因为登录和注销已经工作)!而且您应该能够通过phpLiteAdmin或sqlite3看到您的行。“

:(

EN

回答 1

Stack Overflow用户

发布于 2022-11-10 11:37:07

问题在app.py的索引路径中(未显示)。index.html在这里表示一个名为"company“的变量,<td>{{ summary.company }}</td>。在index函数中,有一个sql选择来获取用户的股票持有量。在该表中,THere不是名为"company“的列。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74378327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档