Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialColby Work
20,422 PointsSingle User Blog/Site with Flask and PeeWee
What would be the best strategy for creating a Single user blog, website with Flask + PeeWee?
Would it essentially be the same as in the Flask social network tutorial, just without having a registration area? Is there anything in Flask that is like Django's superuser?
I imagine it would be the User model with just one instance created in the code. Just want to make sure I am on the right track. Thank you!
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsWhen Django sets up a superuser it's done through the manage.py syncdb
. It basically creates a user in the database for you.
The same is done in the model.initialize function shown in the Build a Social network lesson. Using this you don't need registration since you've established the user in the DB.
Post back if you need more details.
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsThere is something called flask-admin https://flask-admin.readthedocs.org/en/latest/. I have been messing around with it a bit and it works although i am struggling to add a @login_required to the route which is '/admin' grrrrrr.
Chris Freeman
Treehouse Moderator 68,441 PointsCheck out these docs
Have you imported the decorator?
from flask.ext.login import login_required, current_user
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Chris
#yeah I imported login_required
#problem is i dont know what the function is for the route '/admin' and '/admin/tutorial'
# i tried to create a function like so
@app.route('/admin')
@app.route('/admin/tutorial')
@login_required
def admin():
pass # my objective is basically to stop anyone getting to the route '/admin' or '/admin/tutorial'
# but it throws all sorts of error as flask admin probably has its own function for '/admin'
# hope i am making sense
Chris Freeman
Treehouse Moderator 68,441 PointsLooking through the flask-admin docs, it seems you have to roll your own auth. Some stack overflow posts mention using flask-security.
Andreas cormack
Python Web Development Techdegree Graduate 33,011 Pointsfixed the problem using the flask request.
rule= request.path
if rule=="/admin/" or rule=='/admin/tutorial/':
if current_user.is_authenticated == False:
return redirect(url_for('login'))
Chris Freeman
Treehouse Moderator 68,441 PointsGreat job Andreas!
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsAndreas cormack
Python Web Development Techdegree Graduate 33,011 Pointsthanks chris. I will go through the docs once more to see if there is a way around it.