Flask example with POST

Before actually answering your question: Parameters in a URL (e.g. key=listOfUsers/user1) are GET parameters and you shouldn’t be using them for POST requests. A quick explanation of the difference between GET and POST can be found here. In your case, to make use of REST principles, you should probably have: Then, on each URL, you can define the behaviour of different … Read more

ImportError: No Module Named bs4 (BeautifulSoup)

Activate the virtualenv, and then install BeautifulSoup4: When you installed bs4 with easy_install, you installed it system-wide. So your system python can import it, but not your virtualenv python. If you do not need bs4 to be installed in your system python path, uninstall it and keep it in your virtualenv. For more information about virtualenvs, read this

Flask ImportError: No Module Named Flask

Try deleting the virtualenv you created. Then create a new virtualenv with: Then: Now let’s activate the virtualenv Now you should see (flask) on the left of the command line. Edit: In windows there is no “source” that’s a linux thing, instead execute the activate.bat file, here I do it using Powershell: PS C:\DEV\aProject> & .\Flask\Scripts\activate) Let’s install … Read more

Flask ImportError: No Module Named Flask

Try deleting the virtualenv you created. Then create a new virtualenv with: Then: Now let’s activate the virtualenv Now you should see (flask) on the left of the command line. Edit: In windows there is no “source” that’s a linux thing, instead execute the activate.bat file, here I do it using Powershell: PS C:\DEV\aProject> & .\Flask\Scripts\activate) Let’s install … Read more

ModuleNotFoundError: No module named ‘MySQLdb’

After finishing of one of my Flask projects, I uploaded it on github just like everybody else. after a 2-3 months period I downloaded the entire githube repository on another machine to run it. However, the app is not working because the packages are not found giving the following message ModuleNotFoundError: No module named ‘Flask’ … Read more

Flask ImportError: No Module Named Flask

Try deleting the virtualenv you created. Then create a new virtualenv with: Then: Now let’s activate the virtualenv Now you should see (flask) on the left of the command line. Edit: In windows there is no “source” that’s a linux thing, instead execute the activate.bat file, here I do it using Powershell: PS C:\DEV\aProject> & .\Flask\Scripts\activate) Let’s install … Read more

Return JSON response from Flask view

As of Flask 1.1.0 a view can directly return a Python dict and Flask will call jsonify automatically. If your Flask version is less than 1.1.0 or to return a different JSON-serializable object, import and use jsonify.

Flask Template Not found

By default, Flask looks in the templates folder in the root level of your app. http://flask.pocoo.org/docs/0.10/api/ template_folder – the folder that contains the templates that should be used by the application. Defaults to ‘templates’ folder in the root path of the application. So you have some options, rename template to templates supply a template_folder param to have your template folder recognised by the flask … Read more