Sure, you can definitely use Flask as a backend-only server. Just skip over any sections in the documentation and tutorials having to do with Jinja and templates. You won't be needing them. FastAPI would be another option for a Python backend. Answer from nonself on reddit.com
🌐
Ffnext
ffnext.io › blog › python-backend-with-flask-for-beginners
Python Backend with Flask for Beginners
May 23, 2022 - After creating a new python file (app.py) and downloading the required flask dependency (pip install flask), by writing a few lines of code, you can immediately start a web service running on localhost with the following command: python app.py.
🌐
Reddit
reddit.com › r/flask › is flask the tool i want for a basic backend server?
r/flask on Reddit: Is Flask the tool I want for a basic backend server?
March 15, 2023 -

I'm building a very simple React frontend and want to build my backend server in Python.

After reading what Flask is in 4 different places I'm still a bit confused. It's generally described as "a web application framework written in Python."

Is a web application framework designed to return the content that appears on a web page, whereas that would normally live in React (or whatever other FE framework)?

If I only want to spin up a reliable web server with some basic endpoints to be hit by my React web application, is Flask the right tool for me? Or should I go with something else?

Sure, you can definitely use Flask as a backend-only server. Just skip over any sections in the documentation and tutorials having to do with Jinja and templates. You won't be needing them. FastAPI would be another option for a Python backend. Answer from nonself on reddit.com
🌐
Flask
flask.palletsprojects.com
Welcome to Flask — Flask Documentation (3.1.x)
Configuring from Python Files · Configuring from Data Files · Configuring from Environment Variables · Configuration Best Practices · Development / Production · Instance Folders · Signals · Core Signals · Subscribing to Signals · Creating Signals · Sending Signals · Signals and Flask’s Request Context ·
🌐
Full Stack Python
fullstackpython.com › flask.html
Flask - Full Stack Python
Visualize your trip with Flask ... as the backend web framework. Microservices with Flask, Docker, and React teaches how to spin up a reproducible Flask development environment with Docker. It shows how to deploy it to an Amazon EC2 instance then scale the services on Amazon EC2 Container Service (ECS). Build a Video Chat Application with Python, JavaScript ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › flask-tutorial
Flask Tutorial - GeeksforGeeks
1 week ago - Routing: Maps URLs to Python functions using simple decorators. Flexible Database Choice: No built-in ORM, allowing use of tools like SQLAlchemy or raw SQL. API Development: Well-suited for building RESTful APIs and backend services. Development Server: Includes a built-in server for local testing during development. This section introduces Flask, compares it with Django and shows how to install it on Windows to start building web applications.
🌐
MetaCTO
metacto.com › home › blog › development › what is flask? a comprehensive guide to the python backend framework
What Is Flask? A Guide to the Python Backend Framework | MetaCTO
July 6, 2025 - Flask is a backend framework written in Python. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. The framework provides developers with a solid foundation built on sensible defaults, ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-use-python-and-flask-to-build-a-web-app-an-in-depth-tutorial-437dbfe9f1c6
How to use Python and Flask to build a web app — an in-depth tutorial
December 19, 2017 - Overall, flask-base provides a great starting point for making your flask application. Of course the backend may be fairly verbose to code, but as a result, it gives you very granular control over your app.
Find elsewhere
🌐
GitConnected
levelup.gitconnected.com › flask-a-flexible-micro-framework-for-backend-dev-in-python-9cfaf1114095
Flask: A Flexible Micro-Framework for Backend Dev in Python | by Griffin Poole | Level Up Coding
July 1, 2020 - So instead, I decided to use a backend framework written in Python to make the most out of a toolkit better suited for the job I had in mind. ... Flask is a micro framework for web development in the Python language.
🌐
Educative
educative.io › blog › python-flask-tutorial
Python Flask tutorial: Build your first Flask application!
Flask is a micro-framework developed in Python that provides only the essential components - things like routing, request handling, sessions, and so on. It provides you with libraries, tools, and modules to develop web applications like a blog, wiki, or even a commercial website.
🌐
Hyperskill
hyperskill.org › courses › 29-python-backend-developer-with-flask
Python Backend Developer with Flask
Master Python backend using Django for your career goals. Build, deploy, and optimize scalable web apps with skills in API, database management, and security. ... Discover the power of Flask, a Python framework for web development.
Top answer
1 of 1
2

Short answer:

Because your form submission uses a get request, you can use request.args to get parsed contents of query string (see also):

cityname = request.args.get("city_name")

Long answer:

I'm sure you're asking for more than just this piece of code. I took the code you provided and added the missing pieces in-line (please don't do this for production code) and also passed cityname to render_template:

import logging
from datetime import datetime

from flask import render_template, request

from app import app, forms


@app.route("/")
def index():
    return render_template("index.html")


@app.route("/dress")
def dress():
    cityname = request.args.get("city_name")

    # missing in example code
    def temperature_condition():
        return 'temp cond'

    # missing in example code
    def clothes():
        return 'clothes'

    feels_temperature = 'feels temp'  # missing in example code
    weather_description = 'weather desc'  # missing in example code

    temp = str(temperature_condition())
    message = str(clothes())
    feels = feels_temperature
    description = weather_description
    return render_template("dress.html", message=message, temp=temp, feels_temperature=feels,
                           weather_description=description, cityname=cityname)  # also pass cityname

I created a minimalistic dress.html:

<html>
    <body>
        <p>message = {{ message }}</p>
        <p>temp = {{ temp }}</p>
        <p>feels_temperature = {{ feels_temperature }}</p>
        <p>weather_description = {{ weather_description }}</p>
        <p>cityname = {{ cityname }}</p>
    </body>
</html>    

Starting the application via flask run allows me to input a city name into the form field and view the results (for example 'Berlin'):

In order to show the weather description for the chosen city, you could create a function that accepts the city name and retrieves the information from the web (just a rough sketch):

import requests, json
import weatherMappingMessage
from app import dress
from keys import *

def weather_for_city(city_name):
    base_url = "http://api.openweathermap.org/data/2.5/weather?"

    complete_url = base_url + "appid=" + api_key + "&q=" + city_name + "&units=metric"
    response = requests.get(complete_url)

    if response.status_code == 200:
        return response.json()  # assumes your API returns a JSON response
    else:
        # perform some error handling here, maybe apply a retry strategy
        pass

Extract the relevant data from the result of weather_for_city and pass it to render_template like you did for the other variables.

🌐
Quora
quora.com › Is-Flask-backend-or-frontend
Is Flask backend or frontend? - Quora
Answer (1 of 3): In web development, ... somewhere, not in the browser, and that makes it “back end”. Flask, which is written in Python, is back end....
🌐
Swovo
swovo.com › blog › what-is-flask-overview-of-the-flask-python-framework-2024
What is Flask? Overview of the Flask Python Framework in 2026
If your goal is to create a simple ... a built-in development server and speedy debugging functions. Flask is a good choice for backend work in mobile applications....
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-make-a-web-application-using-flask-in-python-3
How To Build a Web Application Using Flask in Python 3 | DigitalOcean
2 weeks ago - Learn how to build a Flask web application from the ground up using Python, covering routes, templates, forms, and deployment.
Top answer
1 of 2
5

If you are using same machine, you do not need to use flask-cors.

Update: As you are using Docker you can use flask-cors to handle CORS.

I found that the AJAX calls were not correct in your JS code. const url = "localhost:5000/test"; does not provide information on request protocol.

I followed these steps to run Flask application successfully using Docker and accessing the /test endpoint using JS outside Docker.

  • I updated AJAX request
  • Added Dockerfile to run Flask application inside Docker
  • Build and run the Dockerfile
  • Get the IP address of running Docker container.
  • Used the IP address in AJAX call in JS code which is outside Docker.

Folder structure:

.
├── backend.py
├── Dockerfile
├── readme.md
└── requirements.txt

requirements.txt:

Flask==1.0.2
Flask-Cors==3.0.7

Dockerfile:

FROM python:3
ENV PYTHONBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
CMD ["python", "backend.py" ]

Build Docker file:

docker build -t flask-docker .

Run Docker:

docker run -p 5000:5000 flask-docker

* Serving Flask app "backend" (lazy loading)
* Environment: production
  WARNING: Do not use the development server in a production environment.
  Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

Get Docker container ID:

docker ps

CONTAINER ID        IMAGE                   COMMAND                CREATED             STATUS              PORTS                    NAMES
69cb7d5d243a        flask-docker            "python backend.py"    15 minutes ago      Up 15 minutes       0.0.0.0:5000->5000/tcp

Get Docker container IP address:

docker inspect --format '{{ .NetworkSettings.IPAddress }}' 69cb7d5d243a  

172.17.0.2

Use this IP address in AJAX request in HTML file:

<html>
<head>
  <title>Frontend</title>
</head>
<body>
  <div id="data"></div>
  <button type="button" id="btn">Grab data</button>
  <script type="text/javascript">
  document.getElementById("btn").addEventListener('click', add);
  function add()
  {
    const api_url = "http://172.17.0.2:5000/test";
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        document.getElementById("data").append(this.responseText);
      }
    };
    xhttp.open("GET", api_url, true);
    xhttp.send();
  }
  </script>
</body>
</html>  

backend.py:

from flask import Flask, request, jsonify
from flask_cors import CORS


app = Flask(__name__)
CORS(app)    

@app.route("/test")
def test():
    return "It's working"    

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000)

Output:

2 of 2
1

Add the following line below app = Flask(__name__):

CORS(app)

Check out flask-cors simple usage

🌐
Medium
medium.com › @kanaecoder › creating-a-full-stack-website-with-react-frontend-and-python-flask-backend-91ec2cbd81e0
Creating a Full Stack Website with React Frontend and Python Flask Backend | by Kanaecoder | Medium
September 22, 2023 - First, we begin by setting up the backend using Flask. Create a new directory for your project and within it, create a new Python file for your Flask application. For instance, you can name it app.py.
🌐
Auth0
auth0.com › home › blog › developing restful apis with python and flask
Developing RESTful APIs with Python and Flask | Auth0
November 18, 2025 - Build RESTful APIs using Python and Flask. This post covers everything from setting up your Flask application and managing dependencies to creating API endpoints and deploying with Docker
🌐
DataCamp
datacamp.com › tutorial › python-backend-development
Python Backend Development: A Complete Guide for Beginners | DataCamp
August 18, 2024 - Python is used mainly for backend development. It is known for its simplicity, readability, and a robust ecosystem of frameworks like Django and Flask, designed for server-side logic, database management, and API development. However, Python can also be used in some frontend tasks, such as ...
🌐
GitHub
github.com › taptorestart › python-backend-examples
GitHub - taptorestart/python-backend-examples: Flask, FastAPI, Django, DRF
Flask, FastAPI, Django, DRF. Contribute to taptorestart/python-backend-examples development by creating an account on GitHub.
Starred by 49 users
Forked by 13 users
Languages   Python 91.6% | HTML 5.9% | JavaScript 1.9% | Python 91.6% | HTML 5.9% | JavaScript 1.9%