Python Forum
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.
Reply
#32
I don't use the environment at all, it goes on my nerve. lol.
Maybe I should just delete that config file.
Reply
#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 = '[email protected]'
    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.
Reply
#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?
Reply
#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?
Reply
#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.
Reply
#37
There is no link to file. That's my issue. :)
But you can see it yourself from 28:00 here.
Reply
#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
Reply
#39
Any idea where to start from if I run to this 404 error.
Error:
Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
I started local server without a problem
Output:
(venv) C:\Python37\kodovi\Projects\flask_official_tutorial\flask-tutorial>flask run * Serving Flask app "flaskr" (lazy loading) * Environment: development * Debug mode: on * Restarting with stat * Debugger is active! * Debugger PIN: 318-132-539 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) 127.0.0.1 - - [03/Oct/2019 23:04:36] "GET / HTTP/1.1" 404 - 127.0.0.1 - - [03/Oct/2019 23:04:36] "GET /favicon.ico HTTP/1.1" 404 -
I'm following flask docs tutorial.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask - Opening second page via href is failing - This site can’t be reached rafiPython1 2 5,434 Apr-11-2018, 08:41 AM
Last Post: rafiPython1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020