phpmyadmin 在公共配置文件页面上显示图像

eufgjt7s  于 2023-10-20  发布在  PHP
关注(0)|答案(1)|浏览(224)

嘿,我是新的 flask ,我正试图使一个登录和注册系统,我也想显示个人资料的照片也是在注册时上传。我可以存储照片,但无法显示,至少我认为这一点。这里是代码。
App.py

@app.route('/register', methods=['GET', 'POST'])
def register():
    msg = ''
    if request.method == 'POST' and 'username' in request.form and 'password' in request.form and 'email' in request.form and 'photo' in request.form:
        username = request.form['username']
        password = request.form['password']
        email = request.form['email']
        photo = request.form['photo']
        cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
        cursor.execute('SELECT * FROM accounts WHERE username = % s', (username, ))
        account = cursor.fetchone()
        if account:
            msg = 'Account already exists !'
        elif not re.match(r'[^@]+@[^@]+\.[^@]+', email):
            msg = 'Invalid email address !'
        elif not re.match(r'[A-Za-z0-9]+', username):
            msg = 'name must contain only characters and numbers !'

registration.html

<form action="{{ url_for('register')}}" method="post" autocomplete="off">
            <div class="msg">{{ msg }}</div>
            <input type="text" name="username" placeholder="Enter Your Username" class="textbox" id="username" required></br></br>
            <input type="password" name="password" placeholder="Enter Your Password" class="textbox" id="password" required></br></br>
            <input type="email" name="email" placeholder="Enter Your Email ID" class="textbox" id="email" required></br></br>
            <input type="file" name="photo" placeholder="File location" class="textbox" id="photo" required></br></br>
            <input type="submit" class="btn" value="Register">
            </form>

display.html

<table class="worddark"></br></br></br></br>
                                <tr>
                                    <td>Username:</td>
                                    <td>{{ account['username'] }}</td>
                                </tr>
                                <tr>
                                    <td>Password:</td>
                                    <td>{{ account['password'] }}</td>
                                </tr>
                                <tr>
                                    <td>Email ID:</td>
                                    <td>{{ account['email'] }}</td>
                                </tr>
                                <tr>
                                    <td>Profile:</td>
                                    <td>{{ account['photo'] }}</td>
                                </tr>

我试图得到的解决方案,显示图像的个人资料

8xiog9wr

8xiog9wr1#

您需要使用html <img>标记并将路由放在src属性中。
如果你只保存了一个名为example.jpeg的图片,你需要在src属性<img src="/your/path/example.jpeg">中指定整个路由。

相关问题