Porter97 / offbrand-tutorial

A social network tutorial built using Flask and Stream!
9 stars 3 forks source link

implement decoration permission_required and admin_required? #1

Open DTHerrera opened 4 years ago

DTHerrera commented 4 years ago

Hello Porter97, how do you implement the use of permission_required decoration and admin_required?

On the other hand there are two data required in the program that are:

STREAM_API_KEY ''#Your API key here STREAM_SECRET ''#Your Secret here

this data as I get it?

thank you very much for your support Kind regards

Porter97 commented 4 years ago

permission_required and admin_required can be used above any routes that you want, case in point:

@main.route('/') @admin_required def index(): return render_template('index.html')

alternatively for permission_required, you need to indicate a minimum permission level to be met:

@main.route('/') @permission_required(Permission.FOLLOW) def index(): return render_template('index.html')

The Stream API Key and Stream Secret are obtained through getstream.io!

Hope this answers your questions

DTHerrera commented 4 years ago

Thanks a lot for your answer.

regardas

DTHerrera commented 4 years ago

Hello Porter, I already have the API KEY and Scret of STREAM, but when I try to execute the command "flask db init" it sends me the following message:

File "C:"Users-DTapia-Downloads-offbrand-react-tutorial-master-app-init.py", line 8, in create_app app.config.from_object(config[config_name]) KeyError: <flask.cli.ScriptInfo object at 0x000001E3E05AB608>

some idea that I'm doing wrong.

On the other hand on the page of "getstream.io" there is a tutorial "https://getstream.io/blog/series-building-a-social-network-with-flask-stream-part-1/" that refers to this page, but the code is very different, you will know where I can download the full code from the tutorial?

Thank you so much for your help.

Best regards.

Porter97 commented 4 years ago

You need to set the flask application in environment variables before trying to initialize the database.

You can do this is command line with:

(Windows) '''set FLASK_APP=application.py'''

Or

(MAC) '''Export FLASK_APP=application.py'''

DTHerrera commented 4 years ago

Okay, thanks, I continue to have the same problem, I think it's necessary to define somewhere the variable "config_name"