Harvard University CS50 Lecture on Flask - flask

I am taking CS50 lecture on Python Flask
https://www.youtube.com/watch?v=oVA0fD13NGI&t=5449s
I am using PyCharm instead of VS Code. Here is my problem.
When I make changes in my PyCharm code and "Save All" I should be able to just "refresh" my browser to see the changes, (That's what the CS50 instructor can do), but I have to Stop and Start my Flask server and then go back to my browser in order to see the change.
Is there something I need to turn on and/or configure in PyCharm so that when I make code changes in a Flask application I can just refresh the browser without having to Stop/Start the Flask server. Thanks in advance for any help on this issue.

if you running your application with flask run in terminal, you can use --debug before run, to run in watch mode like this flask --debug run.
Have another away to run in watch mode.
You can use this code in your main file
if __name__ == "__main__":
app.run(debug=True)
when you run, you have to use python like this python app.py.
You can see more in the flask documents Here

Related

Downloading and finally executing Flask to make it work or connecting to the web

It appears that the program is already installed in Pycharm. I even created a blog about how to do it with pictures.
Nonetheless, it has been a nightmare getting to execute and finally connect on the web.
What code am I missing, I did it all thru Pycharm.
Yes, in order to Install Flask to do web apps. You must pay Pycharm Pro. This is true if you have a windows laptop or desktop. I am not certain about other programs where you can do Python web apps for free. But I will research that.

How to run Django function in Pycharm?

I have some internal utilities I want to develop for my Django project. These are utilities that I need to run mostly in my DEV environment, not in production.
I want to be able to call these from my PyDev IDE or Terminal. Is there a way to call functionality in my Django project without creating a view and using a URL to access it?
I've done several Google searches, but nothing is coming up.
If you open the "Python Console" on Pycharm, it will automatically set django up and then you can basically do anything you could do on a Django view. You can write your function anywhere and import and call them. To do the setup manually, you'll need these for lines of code after launching a Python interpreter:
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'path.to.your.settings')
import django
django.setup()
# Write code using Django models here
you could import them to your PyCharm console starting script. In settings under: Build, Execution, Deployment -> Console -> Python Console -> Starting script

How do i run two command lines in AWS simultaneously?

I have a Django app that I am trying to deploy to AWS.
I need two command lines to run the app. One command line will be used to runserver and another one to run a background task. That is how the app runs in my localserver.
How do I start two command lines in AWS?
As i can understand your django app is currently in development mode, I've used tmux for development mode, this page will guide you better to use tmux. Once you have started a tmux session run python3 manage.py runserver and then detach to the session using ctrl-b then press d and now your app will run even after you exit the shell.
To know more about tmux go through this page.
In case you have to run your app in production mode Don't use above method, run your app with any of nginx or apache2 server. This tutorial can guide you to set up your django app with nginx and gunicorn.
Supervisor is a good way to control that. You can run a lot of processes (like server, migration, collectstatic, Celery) easily.
Additionally, you can ensure that all processes will run again when your machine reboots.
And, as everybody said, you have to install a server in production that supports WSGI in order to run Django properly.

flask development single terminal: continue editing Code without quitting flask

Background: I am new to Flask (and fairly new to python, linux terminal, servers). I have gone through the tutorial http://flask.pocoo.org/docs/1.0/tutorial/.
I am developing on raspberry pi 3, via putty from my PC.
I run flask, according to the tutorial:
export FLASK_APP=flaskr
export FLASK_ENV=development
flask run
According to the tutorial I can make changes to the code and the server will automatically reload.
My issue: I don't know how to make changes to my code without stopping Flask (ctrl+c).
How can I leave Flask, return to the Linux Terminal, edit my code, and then return to the Flask Debugger without stopping Flask each time?
I have reviewed the Flask Docs http://flask.pocoo.org/docs/1.0/ to no avail.
Thanks,
You has to enable the debug mode. Default debug is True in flask
app.run(debug=True) or export DEBUG=True
you can go through this link for Flask configuration
http://flask.pocoo.org/docs/1.0/config/#configuring-from-environment-variables
If you are using Flask >=1.0v you need to set environment in development mode.
export FLASK_ENV='development'

plone change in code not visible in development site

I am very new to plone. I have a project folder in eclipse. I have imported it from the cvs project. I have zope as server and I start zope with ./bin/instance restart. When I make changes in my folder, I cannot see the changes in the development website. I can't seem to find what is happening. I even restarted zope after making changes in python. Can anyone help me with this?
Make sure you start your Zope server with bin/instance fg, most likely the name of the script if you used the Plone universal installer buildout.
To see changes in python code you'll either need to restart the server (CTRL-C then start again) or use something like plone.reload to request a reload of changed code.
When starting your server with the fg command, it is automatically running in debug mode and any templates, resources and skin items are reloaded automatically. Start the server with console or start and it'll run in production mode and templates and such are loaded from disk only once.
See the Plone.org documentation on buildout for more information.
The bin/instance command has a built-in help command, try:
bin/instance help
for a list of supported commands or run:
bin/instance help console
to get help on a specific command; the above example will print the help on the console command.