Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Flask: Making my first web site
#31
Change config.py to:
import os

class Config:
    SECRET_KEY = '12345'
    SQLALCHEMY_DATABASE_URI = 'sqlite:///site.db'
    MAIL_SERVER = 'smtp.googlemail.com'
    MAIL_PORT = 587
    MAIL_USE_TLS = True
    MAIL_USERNAME = 'Test'
    MAIL_PASSWORD = '99999'
What happens when use os.environ.get is that Corey is taking environment variables from his own OS.
This will not be the same for you.

If want look at your environment variables.
>>> import os
>>> 
>>> os.environ
This is done for safety concern for not having these values directly in code,but getting them from OS.
I like better python-dotenv for having environment variable closer to project and not on OS.

You don't have to think of these safety yet,as running the local development server now.
Truman likes this post
Quote
#32
I don't use the environment at all, it goes on my nerve. lol.
Maybe I should just delete that config file.
Quote
#33
(Aug-15-2019, 10:30 PM)Truman Wrote: Maybe I should just delete that config file.
That would not work well at all,as nothing would work Hand

Truman Wrote:I don't use the environment at all, it goes on my nerve. lol.
Then make your own bye using python-dotenv.
Just a quick demo using it in this projects.
Now need to read SECRET_KEY from environment.
import os

class Config:
    SECRET_KEY = os.getenv('SECRET_KEY')
    SQLALCHEMY_DATABASE_URI = 'sqlite:///site.db'
    MAIL_SERVER = 'smtp.googlemail.com'
    MAIL_PORT = 587
    MAIL_USE_TLS = True
    MAIL_USERNAME = 'test@gmail.com'
    MAIL_PASSWORD = '99999'  
Folder file setup add .env,Flask will automatically find this .env file as this feature is integrated in Flask 1.0 -->.
11-Blueprints\
  |-- run.py
  |-- .env
  flaskblog\
.env:
SECRET_KEY='12345'
Now have environment reading in project,and do not need to mess with OS environment variables.
No error in part 11 when i test after doing modifications in my two last post.
Quote
#34
tried to install python-dotenv and this is what I get:
Error:
Usage: pip install [options] <requirement specifier> [package-index-options] ... pip install [options] -r <requirements file> [package-index-options] ... pip install [options] [-e] <vcs project url> ... pip install [options] [-e] <local project path> ... pip install [options] <archive url/path> ... no such option: -d
Now let's see if it works.

edit: Ok, I'm able to start my web site with the new config file that you suggested. Still not sure what exactly is happening but hope that with time it will be clearer. Do we also utilize this python-dotenv from the command line?
Quote
#35
Corey is working with some bash_profile file that just appeared from somewhere. He didn't explain anything.
Could anyone give me a small insight about what that is?
Quote
#36
(Aug-19-2019, 11:31 PM)Truman Wrote: no such option: -d
There is no -d option that you should use it's only:
pip install python-dotenv
Quote:Corey is working with some bash_profile file that just appeared from somewhere.
Link to file.
Quote
#37
There is no link to file. That's my issue. :)
But you can see it yourself from 28:00 here.
Quote
#38
(Aug-21-2019, 10:54 PM)Truman Wrote: There is no link to file. That's my issue. :)
You use Windows then there no bash_profile.
All he dos is taking private in info from his OS(bash_profile),and use it in app.

I do show the same using python-dotenv which make this simpler.
Then getting values from .env that's inside project,and not value from OS(as you can never get as is private for Corey).

As mention don't have to think to much about this now as running a tutorial on local development server.
Just have the values coded in config file as i show in post #32
Truman likes this post
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Web development using Flask and Python kirito85 4 327 Jun-14-2019, 02:13 AM
Last Post: kirito85
  [Flask] html error 405 SheeppOSU 0 186 Jun-08-2019, 04:42 PM
Last Post: SheeppOSU
  [Flask] No application found. SheeppOSU 1 300 Jun-01-2019, 02:58 PM
Last Post: SheeppOSU
  Python, flask, Django Ecniv 5 402 May-02-2019, 04:04 PM
Last Post: buran
  Flask tutorial: kintarowonders 1 555 Mar-27-2019, 07:37 PM
Last Post: nilamo
  About Error (Flask) bescf 1 309 Mar-20-2019, 08:18 PM
Last Post: nilamo
  How to retrieve data from site ROHK 2 288 Mar-01-2019, 12:26 PM
Last Post: ROHK
  Deploy flask app on Heroku Prince_Bhatia 0 460 Feb-20-2019, 09:05 AM
Last Post: Prince_Bhatia
  Flask assertion error mebaysan 1 539 Feb-07-2019, 08:34 PM
Last Post: pascale
  How to deploy flask on wamp Prince_Bhatia 1 751 Jan-30-2019, 02:48 PM
Last Post: snippsat

Forum Jump:


Users browsing this thread: 1 Guest(s)