Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flask-backend
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
retno sonjaya
flask-backend
Commits
2a706cfe
Commit
2a706cfe
authored
Aug 12, 2024
by
Beno Sons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
seed user admin
parent
66308f4a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
1 deletion
+10
-1
README.md
README.md
+3
-0
app/__init__.py
app/__init__.py
+5
-0
app/seeder/seed_users.py
app/seeder/seed_users.py
+2
-1
No files found.
README.md
View file @
2a706cfe
flask db init
flask db init
flask db migrate -m "Initial migration"
flask db migrate -m "Initial migration"
flask db upgrade
flask db upgrade
flask seed_db
------------------------
flask run --port 5001 --reload
flask run --port 5001 --reload
------------------------
SECRET_KEY=your-secret-key
SECRET_KEY=your-secret-key
...
...
app/__init__.py
View file @
2a706cfe
...
@@ -96,4 +96,9 @@ def create_app():
...
@@ -96,4 +96,9 @@ def create_app():
db
.
session
.
rollback
()
db
.
session
.
rollback
()
return
jsonify
({
"code"
:
500
,
"message"
:
"Internal server error"
,
"data"
:
None
}),
500
return
jsonify
({
"code"
:
500
,
"message"
:
"Internal server error"
,
"data"
:
None
}),
500
@
app
.
cli
.
command
(
'seed_db'
)
def
seed_db_command
():
from
app.seeder
import
seed_users
seed_users
()
return
app
return
app
app/seeder/seed_users.py
View file @
2a706cfe
...
@@ -3,7 +3,8 @@ from app.models.user import User
...
@@ -3,7 +3,8 @@ from app.models.user import User
def
seed_users
():
def
seed_users
():
if
not
User
.
query
.
filter_by
(
username
=
'admin'
)
.
first
():
if
not
User
.
query
.
filter_by
(
username
=
'admin'
)
.
first
():
admin
=
User
(
username
=
'admin'
,
password
=
'admin'
)
admin
=
User
(
username
=
'admin'
)
admin
.
email
=
'admin@example.com'
admin
.
email
=
'admin@example.com'
admin
.
set_password
(
'password'
)
db
.
session
.
add
(
admin
)
db
.
session
.
add
(
admin
)
db
.
session
.
commit
()
db
.
session
.
commit
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment