closed, typo : python flask sqlalchemy – get request adds ‘) at the end of searched image file name [closed]

I’ve been following the tutorial and for some reason at the point where the page is requesting the current_user’s image file, there is an ') at the end of the image file name in the get request.

Here’s the model:

from flaskproject import db, login_manager
from datetime import datetime, timezone
from flask_login import UserMixin

class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20), nullable=False, default="default.jpg")
    password = db.Column(db.String(60), nullable=False)

    posts = db.relationship("Post", backref="author", lazy="subquery")

    def __repr__(self):
        return f"User('id={self.id}', '{self.username}', '{self.email}', '{self.image_file}')"

routes.py

from flaskproject import app, db, bcrypt
from flaskproject.forms import RegistrationForm, LoginForm
from flask import render_template, redirect, flash, url_for, request
from flaskproject.models import Post, User
from flask_login import login_user, current_user, logout_user, login_required

@app.route("/my-account/")
@login_required
def my_account():
    return render_template("my-account.html", title="My Account")

The html page:

<div>
  <div>
    <img src="{{ url_for('static', filename='profile-pics/' + current_user.image_file)}}')">
    <div class="">
      <h2 class="">{{ current_user.username }}</h2>
      <p class="">{{ current_user.email }}</p>
    </div>
  </div>
  <!-- FORM HERE -->
</div>

The file structure is:

foldername
--flaskproject
----static
------profile-pics
--------default.jpg
----templates
----__init__.py
----forms.py
----models.py
----routes.py
--run.py

__init__.py

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager

app = Flask(__name__)

SECRET_KEY = "SECRET_KEY"
app.config["SECRET_KEY"] = SECRET_KEY
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///site.db"

db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
login_manager.login_view = "login"
login_manager.login_message_category = "danger"

from flaskproject import routes

run.py

from flaskproject import app

if __name__ == "__main__":
    app.run(debug=True)

Then, when I load the my_account route, the GET request gives me this

"GET /static/profile-pics/default.jpg') HTTP/1.1" 404 -

So, for some reason it includes ') at the end as a part of the file name. I checked the database. Here’s what the image file looks like:

>>>user
User('id=1', 'admin', '[email protected]', 'default.jpg')
>>>user.image_file
'default.jpg'

It should be a normal string, right? At first the route was supposed to include that url_for('static') and pass into the html page, but I changed it to what it is now, straight html url_for, and nothing seemed different; the same ') is at the end of the file name. What seemed most weird to me is that when I tried to do current_user.image_file[:-2], to cut the last 2 characters, and it cut 2 characters BEFORE the ').

What might be the reason for this ') appearing at the end and ruining get request, and how do I fix it?

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật