weijiang1994 / Blogin

A blog system depend on flask.使用flask框架开发的个人博客系统.
https://2dogz.cn
GNU General Public License v3.0
499 stars 97 forks source link

Cannot access into the backend management system #4

Closed SuperTyrael closed 3 years ago

SuperTyrael commented 3 years ago

Why I can't access into the management system when I using the super admin account

weijiang1994 commented 3 years ago

我当初是把通过我的邮箱注册的账号设置为了管理员账号,改为你自己注册的邮箱即可,具体代码修改如下

# Blogin/blogin/models.py
def set_role(self):
    if self.roles is None:
        if self.email == '804022023@qq.com' or self.email == 'weijiang1994_1@qq.com':
            self.roles = Role.query.filter_by(name='ADMIN').first()
        else:
            self.roles = Role.query.filter_by(name='USER').first()
        db.session.commit()

把上面代码的邮箱改为你自己注册邮箱就可以啦~

weijiang1994 commented 3 years ago

看了你的仓库,你应该也是Chinese ~ 方便的话 可以帮我点个star 谢谢啦~

SuperTyrael commented 3 years ago

好的hhhh,还有想问一下SOUL里面几个功能都崩了大概是啥原因

weijiang1994 commented 3 years ago

需要导入对应的数据到数据库中才可以正常运行,获取数据的方法可以查看我的博客,就当做是个练习hhh API

SuperTyrael commented 3 years ago

OK,我现在尝试添加新的文章的时候报错

Traceback (most recent call last):
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask_login/utils.py", line 272, in decorated_view
    return func(*args, **kwargs)
  File "/Users/liam/Desktop/Git/Blogin/blogin/decorators.py", line 39, in decorated_function
    return func(*args, **kwargs)
  File "/Users/liam/Desktop/Git/Blogin/blogin/blueprint/backend/blog_bp.py", line 54, in blog_create
    update_contribution()
  File "/Users/liam/Desktop/Git/Blogin/blogin/utils.py", line 55, in update_contribution
    con.contribute_counts += 1
AttributeError: 'NoneType' object has no attribute 'contribute_counts'
weijiang1994 commented 3 years ago

这个错误原因是数据库中没有插入今天活动数据,我部署在服务器上面是使用的crontab定时任务自动插入数据的,你可以在数据库contribute手动插入一条今天的数据。contribute_counts的数值随便填就可以。这其实也可以算是一个bug

SuperTyrael commented 3 years ago

OK,实在是太谢谢您的分享了,对初学者帮助很大!

SuperTyrael commented 3 years ago

这个插入的数据是什么呢

SuperTyrael commented 3 years ago

在我尝试编辑数据的时候出现了

  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/liam/Desktop/Git/Blogin/env/lib/python3.7/site-packages/flask_login/utils.py", line 272, in decorated_view
    return func(*args, **kwargs)
  File "/Users/liam/Desktop/Git/Blogin/blogin/decorators.py", line 39, in decorated_function
    return func(*args, **kwargs)
  File "/Users/liam/Desktop/Git/Blogin/blogin/blueprint/backend/blog_bp.py", line 103, in blog_content_edit
    with open(history_file_path, 'w', encoding='utf-8') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/liam/Desktop/Git/Blogin/history/a675df48be57be4ce7867e3239e62187.txt'

另外在文章界面也有一些显示问题,比如标题消失了。。。

weijiang1994 commented 3 years ago

你看我博客首页的侧边栏有一个类似github commit统计的热力图 这个数据就是那个热力图的数据基础。具体代码如下

# Blogin/blogin/task.py
@aps.task('cron', id='do_job_3', day='*', hour='00', minute='00', second='50')
def auto_insert_data():
    """
    定时任务,每天00:00:50时刻自动向数据库中插入一条数据,如果数据库中存在了则不作任何动作
    """
    with db.app.app_context():
        date = datetime.date.today()
        contribute = Contribute.query.filter_by(date=date).first()
        visit = VisitStatistics.query.filter_by(date=date).first()
        lk = LikeStatistics.query.filter_by(date=date).first()
        com = CommentStatistics.query.filter_by(date=date).first()

        if not contribute:
            con = Contribute(contribute_counts=0, date=date)
            db.session.add(con)
        if not visit:
            vis = VisitStatistics(date=date, times=0)
            db.session.add(vis)
        if not lk:
            like = LikeStatistics(date=date, times=0)
            db.session.add(like)
        if not com:
            comm = CommentStatistics(date=date, times=0)
            db.session.add(comm)
        db.session.commit()

我的服务已经部署到服务器上面去了,所以一直在运行,不会出现你那种报错。我刚刚修改了那个地方,具体可以看这次的commit https://github.com/weijiang1994/Blogin/commit/e54d0c66c9ce44eb32d701403de1469c24321858

weijiang1994 commented 3 years ago

[Errno 2] No such file or directory 类似于这种错误,你可以在他报错的路径新建对应的目录即可。

SuperTyrael commented 3 years ago

这个原因是为什么。。。title怎么跑到这里来了

image

weijiang1994 commented 3 years ago

清除浏览器缓存试一下

SuperTyrael commented 3 years ago

好了,我研究研究,谢谢您