#I need help setting up setting up mongo Database to flask python
1 messages ยท Page 1 of 1 (latest)
you don't have mongo.py in gmt folder
because i dont have a python folder named mongo
its a package
i dont understand
@verbal imp thx for your attempt btw appreciate you msging me
from .. import means from folder up to current folder import something, if you want import something from installed packages don't put it in relative import
ohh i see the confusion
so the thing is i didnt write this code, im working with a team but i am unable to locally run the html code iv made a local mongo database but after running that i recieved this bugs, i dont really know what to write as i am new to html
i am learning on the way
they are unable to help for reasons so i decided
thats python not html
yeah ik but for that to work i was told this should be fixed
and idk what to import from
do you have any idea what directory is needed to import mail and mongo
or articles etc
show content of gmt/__inint__.py or if its empty what files are in gmt folder
should i show you the code in inint.py
hold on il show you the content
files in gmt folder:
@verbal imp ?
show full error first including command you run
you shouldn't add that view to ..
mongo is local variable to function create_app it cannot be imported in other file
so should i keep it only ..
yes just ..
in file __init__.py at line 11 add mongo = PyMongo() and in line 20 change to mongo.init_app(app)
im installing freepaser now
i have installed it with pip
but it still shows this
thats old error you run twice after that without error
odd it didnt, im a reload vs code
@verbal imp
nice that worked, can u help me take care of the other errors
what it is suppose to be that get_news? function then you don't have such in __init__.py
and judging by the name it don't belong to that file
sorry?
in which file you have get_news function or variable defined?
then why you changed it form this which was correct to just ..
.. means go up one directory if there is nothing more python will check __init__.py file, if your import is in different file you need to add that file name (without .py extension)
so ..news
like this yeah?
ohhh i see
yes
yes
THX SO MUCH BTW I REALLY APPRECIATE IT (You dont know how much this helps lmao)
i have one more enquiry if you dont mind
ask
thx
so
with your help (thx again) i am running on the server however im receiving this problem
how did you open it?
something wrong with templates
config template?
could that be why
idk which one
Do you wanna live share I really want to start coding on my page as soon as possible
Ik I'm putting a lot of work on u but please ๐
its not working in my browser, and have no time
damnn
ight thx alot for your help was really helpful
oh i just realised
Congrats on winning tmt challenge ๐
WAIT IS THIS WHY??
sorry im i pushing it too much
if you don't have runtime errors then don't worry static analyser warnings for some project it require special configuration to work good
ohh i see
but is it not still likley this might be the root cause
i will keep in mind that btw thx
check your browser console for errors and flask log
oh god yeah
check this out
some file names are wrongly generated 7B is encoded {
template is not going through template engine but is served client directly
How did u get that lmao explain so I can do the same
From this how would ik what to fix?
whats the explicit way you found out as in what line and how would i know how to fix it
whats in flask log
il be honest idk where to go for that or how to set it up
its showing here
Oh am i connected to the wrong server?
Because the web opens up automatically as soon as i click open live
Should i change it to 55
lol don't use vscode live server, its only for static websites
Ohh lmaoo
ctr click flask link in console
this one
ask your team members how to config this
idk that flask_wtf lib so can't help
But can you tell me
How did u get this
Im interested and want to learn
this is flask template engine syntax (by default jinja2), jinja replace this with generated html, so if you see this on page that means jinja didn't parse it
same is here %XX is some special char encoded to be safely used in URL, you can google them %7B is { and %7D is } and %20 is space so its {{ url_for(...) }} its jinja syntax
csrf is acronym for hackers attack method Cross-Site Request Forgery and in flask its module to secure your app against this attacks
Il search it up for more info
Also should i leave mongo is not defined
Hold on so how does csrf affect that
Oh you went offline: Thx for all of ur help so far, i hope u can answer my q when ur online again @verbal imp
no this wasn't caused by csrf this was cos you didn't open page served by flask but served by vscode which is not using flask so no dynamic generated content
so how would i open page served by flask
and what will fixing csrf have a effect on?
will fix this error
you did opened it already (ctrl + click on link in console, or you can type that address manually in browser) as on same screen you can see get requests
to fix that error and other possible check if you have config.py filled with values if not you need to set all this environmental variables
Ah alr, techinically i didnt open it with flask cus when i closed vscode and reran innit.py it didnt provide me with any link
So all these variables need to be configured
all that are used by some code i don't know how much code is already implemented and how much of them are used
How would i check
you can search for them in source or add them when you see errors so for now you need SECRET_KEY, MONGO_URI is overwritten in __init__.py its ok till you use local development db, it needs to be changed when website will be deployed
How would overwritten
Im confused
here is hardcoded instead loaded from config/environment variable

this line app.config should not exists and next mongo.init_app(app) should be below load_configuration(app), what is now is ok till you run on your machine during developing process, but shouldn't ever reach deployment
this mongo URI should be saved as environmental variable or in config.py that should never be checked in repository and in production only environmental variable should be used no config.py
If its ok then why do i get the errors
i say only MONGO_URI currently is ok and it don't give you error
SECRET_KEY which gives you error you need to set
So that i dont neee to worry about when im developing the pages
Ohh i see so it shouldnt reach deployment
are you talking about these fields
Is this what ur saying or no?
so they give you clear instruction to follow and you didn't
No i just found it 
This is for configuration right?
And that will fix the errors right??
if you follow all of them and don't make mistake then yes it should work
Yeah thx, so that would then allow the pages to be dynamic generated content
if you don't use vscode live preview but flask server then yes
I should use what because i dont get the link anymore
It onlr runs when i use vscode live preview
you need to see this
if you don't it will not work
and trying to use live preview is completely pointless
Thats the thing i dont see that anymore i just see thr flask logs
if you see flask logs thats ok
this means server is running and request comes to flask
you can use ctrl-c to stop it and if you run again you'll see again whats on above image
Ah ic after pressing ctrl c il get the link again and i just go to that right?
yes, some changes in code can be seen when flask is running, for most you need restart flask server
no thats page on client side
flask server is on this image what python is running
Ohh i see by pressing ctrl c i am restartung the flask server?
pressing ctr -c and staring server again, as ctrl-c only stops server
Ahh yeah i get it
So
After i configure it and go to a html page it should be showing dynamic content right?
yes if flask starts without errors
Ayy nice so only configuration is left?
And also in what instance would i use the go live rather than the flask server
if you write static page only
where static means everything happens on client side there is no need to talk to server except download files that are stored on server (server don't generate nothing in runtime)
So u wouldnt run a home page with that as it is dynamic
its not single page from whole website that needs to be static or dynamic its whole website that need to be static
Hold on but am i not running static cus it says u would use html and css
How would u know the website im working on is dynamic is it because of flask
And syntax
you always use html and css as that whats needed for browser to display page
Yeah make sense
if you write code that will run on server side thats when website is dynamic, and yes flask is framework to run on server, browser can't run python code
yw
Have a nice day tovis
@verbal imp hey Yan ๐ need help
sorry to disturb you again, hope you can help
what cmd you used?
i used cd (the directory) mkdir instance
which created a folder
i then moved config templates inside instance and renamed it to
as well as doing pip install -r requirements.txt
show full current error
show file tree from vscode
dont use windows explorer to rename files or turn on show file extension
it need to be named config.py not config.py.py
right click in vscode and choose rename
done but still shows
ohh becuase i renamed config.template to config.py it does not recognise where to from
is that why?
does that help?
this line is not orginaly in that file,
why did you added it? you should read config from app.config dictionary not from file and why do you need MONGO_URI in that file you shouldn't create another connection to data base but use already existing
so what should it be instead? 
from .. import mongo as it was orginaly if you want query db use this mongo variable look how its done in other functions in that file
should i take this out completely then ?
is it not the app.config dictionary
thats just specifying it manually
in index.py yes this line is not needed, same in __init__.py modify config.py and change it there
what line and what file
probably you should delete it all clone from beginning follow the steps in readme to install and configure then run without touching any code (except config.py) if website is running correctly then do your changes to code
alr let me try that
should i just copy my current code in config py and place it in the new clone
@verbal imp
from the start
Right back where we started :/
Yeah
add in __init__.py in line 76 (move mongo.inint_app(app) one line down) print(app.config["MONGO_URI"])
like this?
should i run index
yes
well i havnt did configuration/ the instruction from readme yet ๐
ill do it now lmaoo
OH MYY , im actually so sorry for my stupidity i could avoided wasting u time for hours.im really sorry
you learnt something, remember if you clone some project first make it run before you do any changes, and good project will have instructions how to set it up
if its working remove that print you added
yeah will do, im so sorry thx alot for coping with me and being so patient