Coder Social home page Coder Social logo

simple-webapp-flask's Introduction

Simple Web Application

This is a simple web application using Python Flask and MySQL database. This is used in the demonstration of the development of Ansible Playbooks.

Below are the steps required to get this working on a base linux system.

  • Install all required dependencies
  • Install and Configure Web Server
  • Start Web Server

1. Install all required dependencies

Python and its dependencies

apt-get install -y python3 python3-setuptools python3-dev build-essential python3-pip default-libmysqlclient-dev

2. Install and Configure Web Server

Install Python Flask dependency

pip3 install flask
pip3 install flask-mysql
  • Copy app.py or download it from a source repository
  • Configure database credentials and parameters

3. Start Web Server

Start web server

FLASK_APP=app.py flask run --host=0.0.0.0

4. Test

Open a browser and go to URL

http://<IP>:5000                            => Welcome
http://<IP>:5000/how%20are%20you            => I am good, how about you?

simple-webapp-flask's People

Contributors

mmumshad avatar suyogpatil avatar tanbir2684 avatar tej-singh-rana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simple-webapp-flask's Issues

pip install not working

Hi,

The old docker file is not working getting error -> I have updated the docker file (Thank You for your docker course)

FROM ubuntu
RUN apt-get update && apt-get install -y python3 python3-pip
RUN pip install Flask
COPY app.py /opt/
ENTRYPOINT FLASK_APP=/opt/app.py flask run --host=0.0.0.0 --port=8080

Port Mapping issue

Hi,
As we have mentioned port no. inside the code as 8080, now if we want to do the port mapping to expose the application publicly which port number should I use for port mapping 8080 or 5000

The second thing is when we hit this URL inside (Not publicly) we are using port 5000 why 5000? because we did not mention 5000 anywhere in the code we have used port 8080 inside the code.

/bin/sh: 1: flask: not found

When running the image in docker throws an error

C:\Windows\System32\my-webapp>docker run -p 8080:8080 my-webapp

  • Serving Flask app 'app.py' (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: off
    Usage: flask run [OPTIONS]
    Try 'flask run --help' for help.

Error: Could not import 'app'.

NOT-WORKING

root@master:~/my-simple-webapp# docker run my-simple-webapp

  • Serving Flask app 'app.py' (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: off
    Usage: flask run [OPTIONS]
    Try 'flask run --help' for help.

Error: Could not import 'app'.

FLASK_APP: not found

Hi Mumshad,

Getting error message , FLASK_APP: not found when i try to execute command
docker run -p host port: container port docker image-name

Created a docker file using sample code provided in simple-webapp-flask application. Created an image, but when i execute the above command, get error message flask:app not found.

Below is the code snippet for app.py and docker file

app.py

import os
from flask import Flask
app = Flask(name)

@app.route("/")
def main():
return "Welcome!"

@app.route('/how are you')
def hello():
return 'I am good, how about you?'

if name == "main":
app.run(host="0.0.0.0", port=8080)

Dockerfile

FROM ubuntu
RUN apt-get update
RUN apt-get install -y python3 python3-pip
RUN pip install flask
COPY app.py /opt/app.py
ENTRYPOINT FLASK_APP = /opt/app.py flask run --host=0.0.0.0

could you pls advice

regards
Saravanan

Not working for me

root@829e3edc10af:/opt# FLASK_APP=app.py flask run --host=0.0.0.0

  • Serving Flask app 'app.py' (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: off
    Traceback (most recent call last):
    File "/usr/local/bin/flask", line 8, in
    sys.exit(main())
    File "/usr/local/lib/python3.8/dist-packages/flask/cli.py", line 990, in main
    cli.main(args=sys.argv[1:])
    File "/usr/local/lib/python3.8/dist-packages/flask/cli.py", line 596, in main
    return super().main(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
    File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/flask/cli.py", line 845, in run_command
    app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
    File "/usr/local/lib/python3.8/dist-packages/flask/cli.py", line 321, in init
    self._load_unlocked()
    File "/usr/local/lib/python3.8/dist-packages/flask/cli.py", line 346, in _load_unlocked
    self._app = rv = self.loader()
    File "/usr/local/lib/python3.8/dist-packages/flask/cli.py", line 402, in load_app
    app = locate_app(self, import_name, name)
    File "/usr/local/lib/python3.8/dist-packages/flask/cli.py", line 256, in locate_app
    import(module_name)
    File "/opt/app.py", line 9
    @app.route('/how are you')
    ^
    IndentationError: unindent does not match any outer indentation level

chages made to solve problem

FROM ubuntu:16.04
RUN apt-get update && apt-get install -y python3 python3-pip
RUN python3 -m pip install flask
COPY app.py /opt/
ENTRYPOINT FLASK_APP=/opt/app.py flask run --host=0.0.0.0 --port=8080

why MySQL?

Hello,
Is it really necessary to install MySQL for this simple-webapp-flask? If yes, why?
Regards,

IM

Simple Web App

Section 2 shows the following;

Copy app.py or download it from source repository
Configure database credentials and parameters

Can you explain where to put the app.py file and how to configure database credential and parameters?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.