0% found this document useful (0 votes)
37 views

Build From Zero A Simple App

The document describes how to create a simple website with HTML, CSS, JavaScript, PHP and a SQL database locally on one's computer. It provides steps to set up the files and directories, connect a PHP script to a SQL database to handle form submissions and data storage, and test the website using a local server like WAMP. The response addresses additional questions about the specifics of coding the HTML, PHP, and modifying the PHP script to retrieve and display past submissions from the database.

Uploaded by

Pablo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Build From Zero A Simple App

The document describes how to create a simple website with HTML, CSS, JavaScript, PHP and a SQL database locally on one's computer. It provides steps to set up the files and directories, connect a PHP script to a SQL database to handle form submissions and data storage, and test the website using a local server like WAMP. The response addresses additional questions about the specifics of coding the HTML, PHP, and modifying the PHP script to retrieve and display past submissions from the database.

Uploaded by

Pablo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

I want to create a very simple website with html, css, javascript, php and a sql database in

local, in my computer. In this very simple website, there will be two text boxes: the user will
write a name in one, and a gossip about him. He will click on a button to send the message.
The message "Thank you for telling us about [name of the person]: Here you have more
information about [name of the person]". It will show other messages about that person. Can
you tell me how to do it?
To create a simple website with HTML, CSS, JavaScript, PHP, and a SQL database on your

local computer, you will need to follow these general steps:

1. Create a new directory on your computer to store your website files.


2. Use a text editor to create the HTML, CSS, and JavaScript files for your website. The
HTML file should include the structure and layout of the page, the CSS file should
include the styles for the page, and the JavaScript file should include any interactive
functionality for the page.
3. Use PHP to create a script that will handle the form submission and database
interactions. The script should take the input from the text boxes, insert it into the
SQL database, and return a message to the user.
4. Install a local web server (e.g. Apache) and a database management system (e.g.
MySQL) on your computer.
5. Connect your PHP script to the SQL database using the appropriate database driver
(e.g. mysqli or PDO).
6. Use SQL to create the necessary tables in the database to store the data.
7. Test the website by running it on your local web server and accessing it through your
web browser.
8. Finally, customize the CSS of the website and add some JavaScript functionality to
make it more interactive

Keep in mind that this is a high-level overview, and there may be many more specific steps

and considerations depending on the tools and technologies you choose to use.

What do I write in this HTML?


In the HTML file for your website, you will need to write the structure and layout of the page.

This will include elements such as the head, which contains meta information about the
page, and the body, which contains the content of the page. Here's an example of what the

HTML for your website might look like:

Copy code

<!DOCTYPE html> <html> <head> <title>Gossip Website</title> </head> <body> <h1>Gossip</h1> <form

action="submit.php" method="post"> <label for="name">Name:</label> <input type="text" id="name"

name="name"> <br> <label for="gossip">Gossip:</label> <input type="text" id="gossip" name="gossip"> <br>

<input type="submit" value="Submit"> </form> </body> </html>

In this example, the form element is used to create a form with two text boxes, one for the

name and one for the gossip. The form's action attribute is set to "submit.php" and the

method attribute is set to "post", indicating that the form data will be sent to the "submit.php"

script using the HTTP POST method.

You could also use a div for the messages, and use JavaScript to populate the div with the

messages retrieved from the database, and you could use CSS to style the website.

Also, you could use a table to show the messages and the name of the person in the gossip,

and use php to populate the table with the information retrieved from the database.

Keep in mind that this is just one example, and you can customize and adjust the HTML to

suit your needs.

What should I write in the file submit.php?


The submit.php file should contain the PHP script that will handle the form submission and

database interactions. Here's an example of what the script might look like:

Copy code

<?php // Connect to the database $servername = "localhost"; $username = "your_username"; $password =

"your_password"; $dbname = "your_dbname"; $conn = new mysqli($servername, $username, $password,


$dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Retrieve the

form data $name = $_POST['name']; $gossip = $_POST['gossip']; // Insert the data into the database $sql =

"INSERT INTO gossips (name, gossip) VALUES ('$name', '$gossip')"; if ($conn->query($sql) === TRUE) {

echo "Thank you for telling us about $name: Here you have more information about $name"; } else { echo

"Error: " . $sql . "<br>" . $conn->error; } $conn->close();

In this example, the script first connects to the database using the mysqli extension and the

provided credentials ($servername, $username, $password, $dbname).

Then the script retrieves the form data by using the $_POST superglobal, which is an array

that contains the data sent via the HTTP POST method.

The script then creates an SQL statement and uses it to insert the form data into the gossips

table.

It then checks if the query was successful or not. If it was successful, the script echoes a

message "Thank you for telling us about [name of the person]: Here you have more

information about [name of the person]" to the user. If not, it echoes an error message with

the error that occurred.

Finally, the script closes the database connection.

It's important to note that this is a very basic example and you should sanitize the input

before using it in the query to avoid SQL injection and also should use prepared statements.

Also, you could use a SELECT statement to retrieve the messages from the database, and

use a while loop to iterate through the results and echo them in the HTML.

how should i name the html file?


You can name the HTML file whatever you like, as long as it has the ".html" or ".htm" file

extension. The most common name for the main page of a website is "index.html" or

"index.htm". Naming the file "index.html" or "index.htm" is a convention that many web

servers follow, which means that when a user visits the root of a website, the web server will

automatically look for a file named "index.html" or "index.htm" and serve it as the default

page for the website.

If you name your HTML file something other than "index.html" or "index.htm", you will need to

include the name of the file in the URL when accessing it. For example, if you name your

HTML file "gossip.html", you would access it by visiting

"http://yourwebsite.com/gossip.html" instead of just "http://yourwebsite.com/".

You could also use a PHP file, where you could write the HTML code in the PHP file, and

name it index.php.

I have created the HTML, the PHP script, installed Apache and MySQL, created the tables to
store the data. How can I test the website? I have wampserver64 installed. My Operating
System is Windows.
To test your website on your local computer with WAMP server installed, you can follow

these steps:

1. Save the HTML, CSS, JavaScript, and PHP files for your website in the "www"
directory of the WAMP installation. This is typically located in the "C:\wamp64\www"
directory.
2. Start the WAMP server by clicking on the WAMP icon in the system tray and selecting
"Start All Services"
3. Open a web browser and navigate to "http://localhost/" or "http://127.0.0.1/". You
should see the default WAMP start page.
4. In the browser's address bar, type "http://localhost/your_html_file.html" or
"http://127.0.0.1/your_html_file.html" (replace "your_html_file.html" with the name of
your HTML file). This will load your website in the browser.
5. Test the form by filling in the textboxes and clicking the submit button. Check if the
information is stored in the database, if you can retrieve the information, and if the
website is showing the right message.
6. If you have any issue, you can check the error log of Apache, in the
"C:\wamp64\logs\apache_error.log" file, and the error log of MySQL in the
"C:\wamp64\logs\mysql.log" file.

It's important to note that this is just a basic example, and you may need to make

adjustments based on your specific setup and configuration.

Also, you should note that if you're using a different version of WAMP, the path to the www

folder and the error logs may be different.

Please, modify the file submit.php. After the sentence "Thank you for telling us about $name:
Here you have more information about $name", it will have to print the last five gossips about
that person it can find in the database
Here's an example of how you could modify the submit.php file to display the last five gossips

about the person after the initial message:

Copy code

<?php // Connect to the database $servername = "localhost"; $username = "your_username"; $password =

"your_password"; $dbname = "your_dbname"; $conn = new mysqli($servername, $username, $password,

$dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Retrieve the

form data $name = $_POST['name']; $gossip = $_POST['gossip']; // Insert the data into the database $sql =

"INSERT INTO gossips (name, gossip) VALUES ('$name', '$gossip')"; if ($conn->query($sql) === TRUE) {

echo "Thank you for telling us about $name: Here you have more information about $name <br>"; } else {

echo "Error: " . $sql . "<br>" . $conn->error; } // Retrieve the last 5 gossips about the person $sql = "SELECT

gossip FROM gossips WHERE name = '$name' ORDER BY id DESC LIMIT 5"; $result = $conn->query($sql); if

($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "Gossip: " .

$row["gossip"]. "<br>"; } } else { echo "No gossips found for $name"; } $conn->close();
In this example, after the initial message, the script creates a new SQL query that retrieves

the last five gossips about the person. It uses the ORDER BY id DESC LIMIT 5 clause in the

SELECT statement to sort the gossips by ID in descending order, and then retrieve only the

first five rows.

Then the script uses a while loop to iterate through the results and echo each gossip in the

HTML.

It is important to note that the SQL statements in this example do not use prepared

statements, it's highly recommended to use them to avoid SQL injection.

Also, you should sanitize the input of the variables used in the query before using them, to

avoid SQL injection.

What is SQL injection?


SQL injection is a type of security vulnerability that occurs when an attacker is able to insert

malicious code into a SQL statement, usually by manipulating the data input into a web

application. This can allow the attacker to gain unauthorized access to a database, modify or

delete data, or even execute arbitrary commands on the host system.

The most common way to perform SQL injection is by including user input directly in a SQL

statement, without properly sanitizing or validating the input. For example, if a web

application is using a SQL statement like this:

Copy code

SELECT * FROM users WHERE username = '$username' AND password = '$password';

An attacker could supply the following values for the $username and $password variables:

Copy code
$username = "'; DROP TABLE users; --" $password = "anything"

The resulting SQL statement would look like this:

Copy code

SELECT * FROM users WHERE username = ''; DROP TABLE users; --' AND password = 'anything';

This would drop the "users" table, removing all the data in the table.

To prevent SQL injection, it's recommended to use prepared statements and/or

parameterized queries. These methods use placeholders in the SQL statement, which are

then replaced with the actual data at the time the statement is executed. This ensures that

any malicious input is treated as a string value, and not as part of the SQL statement.

Also, it's important to validate and sanitize any user input before using it in a query.

It's important to mention that SQL injection is not limited only to SQL, it can happen in any

query language such as NoSQL databases.

i get the following error: Trying to get property 'num_rows' of non-object in


C:\wamp64\www\submit.php on line 29
The error message "Trying to get property 'num_rows' of non-object" usually occurs when

you are trying to access a property or method of a variable that is not an object. In this case,

it's likely that the $result variable is not an object, which means that the query did not return

any results.

There could be a few reasons why the query is not returning any results:

● The table or the database might not exist.


● There might be a typo in the table or database name.
● There might be a problem with the SQL query itself, such as a syntax error or a
missing column name.
● The name passed in the query might not match any record in the table.

To troubleshoot the problem, you can try the following:

● Verify that the table and the database exist by using the command line client or a GUI
client to connect to the database, and check if the table is visible.
● check the spelling of the table and the database name in the PHP script.
● Print the query and check if the SQL syntax is correct and if all the columns and
tables are spelled correctly.
● Print the $name variable, to check if it's passing the correct value.
● Add error reporting to your script to see the detailed error message and trace the
error.

Copy code

error_reporting(E_ALL); ini_set('display_errors', 1);

If the issue persist, please let me know, and I'll help you to troubleshoot the problem.

I have solved the problem. When it shows me other gossips about that person, it doesn't
allow me to go back to the main page to insert another gossip. Can you add a return button?
Yes, you can add a "return" button to your website that will take the user back to the main

page where they can insert another gossip. Here's an example of how you could do that:

Copy code

<form action="submit.php" method="post"> <label for="name">Name:</label> <input type="text" id="name"

name="name"> <br> <label for="gossip">Gossip:</label> <input type="text" id="gossip" name="gossip"> <br>

<input type="submit" value="Submit"> </form> <br> <!-- Add a return button --> <form action="index.html">

<input type="submit" value="Return"> </form>


In this example, a new form element is added, with the action attribute set to "index.html", and

the method attribute set to "get". It contains an input element with the type "submit" and the

value "Return". When the user clicks on this button, the browser will navigate to the

"index.html" file.

You could also use a link instead of a form, like this:

Copy code

<a href="index.html">Return</a>

You could also use JavaScript to redirect the user to the main page, like this:

Copy code

<input type="button" value="Return" onclick="location.href='index.html'">

It's important to note that this is just one example, and you can customize and adjust the

HTML to suit your needs.

Ok I want to do the same thing with html, php and Python Flask. Which are the steps?
Here are the general steps you would need to follow to create a simple website with HTML,

PHP, and Python Flask:

1. Install Python and Flask: Make sure you have Python and Flask installed on your
computer. You can download Python from the official website and install it. Once
Python is installed, you can install Flask using pip by running the command pip install
flask
2. Create a new directory for your project and navigate to it in the command line.
3. Create an HTML file that will serve as the template for your website. This file should
contain the structure and layout of your website, including elements such as the
head, which contains meta information about the page, and the body, which contains
the content of the page.
4. Create a Python file that will serve as the main script for your website. This file
should import the Flask module and create a Flask application.
5. In the Python file, create a route for the root URL of your website using the @app.route
decorator. This route should return the HTML template created in step 3.
6. Create another route for the form submit, this route should handle the data sent by
the form and insert it into the database
7. Create another route that will retrieve the data from the database and show it to the
user.
8. Run the Python script with the command flask run
9. Open a web browser and navigate to "http://localhost:5000/", the website should be
displayed
10. Test the form by filling in the textboxes and clicking the submit button. Check if the
information is stored in the database, if you can retrieve the information, and if the
website is showing the right message.

Please keep in mind that this is a high-level overview and there are many details and

nuances to consider when building a website with Flask.

It's also important to mention that you should use a database library such as SQLAlchemy, a

framework that allows you to interact with

Can you write again the HTML file for this case?
Sure, here's an example of what the HTML file for your website could look like:

Copy code

<!DOCTYPE html> <html> <head> <title>Gossip Website</title> </head> <body> <h1>Tell us a gossip</h1>

<form action="submit_gossip" method="post"> <label for="name">Name:</label> <input type="text"

id="name" name="name"> <br> <label for="gossip">Gossip:</label> <input type="text" id="gossip"

name="gossip"> <br> <input type="submit" value="Submit"> </form> <br> <a href="index.html">Return</a>

</body> </html>
In this example, the form has an action of "submit_gossip" and a method of "post", this will

send the data to the Python route that we'll create later on. The form contains two inputs,

one for the name and another for the gossip, and a submit button.

You could add some CSS to format the form and the website.

Also, you could add an ID to the form to use JavaScript to handle the form submission, for

example, by using the fetch() method.

It's important to note that this is just one example, and you can customize and adjust the

HTML to suit your needs.

Can you write the Python file?


Sure, here's an example of what the Python file for your website could look like using Flask:

Copy code

from flask import Flask, render_template, request from flask_sqlalchemy import SQLAlchemy app =

Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' db =

SQLAlchemy(app) class Gossip(db.Model): id = db.Column(db.Integer, primary_key=True) name =

db.Column(db.String(80), nullable=False) gossip = db.Column(db.String(120), nullable=False)

@app.route('/', methods=['GET']) def index(): return render_template('index.html')

@app.route('/submit_gossip', methods=['POST']) def submit_gossip(): name = request.form['name'] gossip

= request.form['gossip'] new_gossip = Gossip(name=name, gossip=gossip) db.session.add(new_gossip)

db.session.commit() return "Thank you for telling us about {}".format(name)

@app.route('/gossips/<name>', methods=['GET']) def gossips(name): gossips =

Gossip.query.filter_by(name=name).all() return render_template('gossips.html', name=name,

gossips=gossips) if __name__ == '__main__': db.create_all() app.run(debug=True)


In this example, the Python file creates a Flask application and set the SQLAlchemy

configuration. Then it creates a Gossip class that inherits from db.Model, this class will be

used as a representation of the table in the database.

Then it defines three routes, the first one is for the main page, the second one is for the form

submission and the third one is to show the gossips.

In the submit_gossip route, it retrieves the data sent by the form, creates a new Gossip

object, adds it to the session and commits the session.

In the gossips route, it retrieves the gossips from the database with the name passed

I want to continue using mysql, can you rewrite the last script? I will use the same database
with the same credentials ("localhost", "your_username", "your_password", "your_dbname")
Sure, here's an example of what the Python file for your website could look like using Flask

and MySQL:

Copy code

from flask import Flask, render_template, request from flask_sqlalchemy import SQLAlchemy app =

Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] =

'mysql://your_username:your_password@localhost/your_dbname' db = SQLAlchemy(app) class

Gossip(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80),

nullable=False) gossip = db.Column(db.String(120), nullable=False) @app.route('/', methods=['GET']) def

index(): return render_template('index.html') @app.route('/submit_gossip', methods=['POST']) def

submit_gossip(): name = request.form['name'] gossip = request.form['gossip'] new_gossip =

Gossip(name=name, gossip=gossip) db.session.add(new_gossip) db.session.commit() return "Thank you

for telling us about {}".format(name) @app.route('/gossips/<name>', methods=['GET']) def gossips(name):

gossips = Gossip.query.filter_by(name=name).all() return render_template('gossips.html', name=name,

gossips=gossips) if __name__ == '__main__': db.create_all() app.run(debug=True)


In this example, the only difference is the SQLAlchemy configuration, the

app.config['SQLALCHEMY_DATABASE_URI'] line is set to the MySQL connection string, it includes

the username, password, host, and database name.

Also, you need to make sure that you have the MySQL connector for python installed in your

environment, you can install it via pip by running pip install mysql-connector-python

Please make sure to replace your_username, your_password, and your_dbname with the actual

credentials of your database.

It's important to mention that you should use prepared statements and/or parameterized

queries to avoid SQL

Why id has a different colour inside class Gossip?


The different color of the "id" variable inside the "Gossip" class is due to the fact that it's a

variable that is being used as a column for the database table and it's being defined as a

primary key.

In this case, the db.Column function is being used, which is a function provided by the

Flask-SQLAlchemy library, and it's used to define the columns of a database table. The

db.Integer and db.String are the types of the columns, and primary_key=True is an optional

argument that specifies that the column is the primary key of the table.

This is a way of defining a database table using the ORM (Object-relational mapping)

provided by the Flask-SQLAlchemy, it allows you to define the structure of the table using

Python classes and methods, instead of writing raw SQL statements, it's a more convenient

way of creating tables and interacting with the databases.


The highlighting is a feature of the development environment or the code editor that you are

using, it helps you to easily identify the different elements of the code and make it more

readable.

The last script must add the new gossip to the table called "gossips"
You're correct, my apologies for the oversight. Here's an example of how you can modify the

Python script to add the new gossip to a table called "gossips":

Copy code

from flask import Flask, render_template, request from flask_sqlalchemy import SQLAlchemy app =

Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] =

'mysql://your_username:your_password@localhost/your_dbname' db = SQLAlchemy(app) class

Gossip(db.Model): __tablename__ = "gossips" id = db.Column(db.Integer, primary_key=True) name =

db.Column(db.String(80), nullable=False) gossip = db.Column(db.String(120), nullable=False)

@app.route('/', methods=['GET']) def index(): return render_template('index.html')

@app.route('/submit_gossip', methods=['POST']) def submit_gossip(): name = request.form['name'] gossip

= request.form['gossip'] new_gossip = Gossip(name=name, gossip=gossip) db.session.add(new_gossip)

db.session.commit() return "Thank you for telling us about {}".format(name)

@app.route('/gossips/<name>', methods=['GET']) def gossips(name): gossips =

Gossip.query.filter_by(name=name).all() return render_template('gossips.html', name=name,

gossips=gossips) if __name__ == '__main__': db.create_all() app.run(debug=True)

In this example, I added the __tablename__ = "gossips" line, this line sets the name of the table

that the Gossip class will be mapped to.

Please make sure that the table "gossips" already exists in your database, otherwise, you will

get an error. If you are using a SQLAlchemy, you can use the db.create_all() method to create

the table if it doesn't exist.


Also, make sure to replace your_username, your_password, and your_dbname with the actual

credentials of your database.

Can you add db.create_all() to the script?


Sure, here's an example of how you can modify the Python script to include the db.create_all()

method, which will create the table if it doesn't exist:

Copy code

from flask import Flask, render_template, request from flask_sqlalchemy import SQLAlchemy app =

Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] =

'mysql://your_username:your_password@localhost/your_dbname' db = SQLAlchemy(app) class

Gossip(db.Model): __tablename__ = "gossips" id = db.Column(db.Integer, primary_key=True) name =

db.Column(db.String(80), nullable=False) gossip = db.Column(db.String(120), nullable=False)

@app.route('/', methods=['GET']) def index(): return render_template('index.html')

@app.route('/submit_gossip', methods=['POST']) def submit_gossip(): name = request.form['name'] gossip

= request.form['gossip'] new_gossip = Gossip(name=name, gossip=gossip) db.session.add(new_gossip)

db.session.commit() return "Thank you for telling us about {}".format(name)

@app.route('/gossips/<name>', methods=['GET']) def gossips(name): g

OK thank you
You're welcome! I'm glad I could help. If you have any other questions or need further

assistance, don't hesitate to ask.


I want the last 5 gossips about that person to be shown once you have send a new gossip
Sure, here's an example of how you can modify the submit_gossip() function to retrieve the last

5 gossips about that person and display them after a new gossip is submitted:

Copy code

@app.route('/submit_gossip', methods=['POST']) def submit_gossip(): name = request.form['name'] gossip

= request.form['gossip'] new_gossip = Gossip(name=name, gossip=gossip) db.session.add(new_gossip)

db.session.commit() last_gossips =

Gossip.query.filter_by(name=name).order_by(Gossip.id.desc()).limit(5).all() return

render_template('gossips.html', name=name, gossips=last_gossips)

In this example, after a new gossip is added and committed to the database, I query the

database to retrieve the last 5 gossips about the person whose name is equal to the name of

the person submitted in the form.

The Gossip.query.filter_by(name=name) filters the gossips by the person's name, the

order_by(Gossip.id.desc()) orders the result by id in descending order, and `limit(

Write the gossips.html file please


Sure, here's an example of what the gossips.html file could look like:

Copy code

<!DOCTYPE html> <html> <head> <title>Gossip Website</title> </head> <body> <h1>Last 5 gossips about {{

name }}</h1> <ul> {% for gossip in gossips %} <li>{{ gossip.gossip }}</li> {% endfor %} </ul> <br> <a

href="index.html">Return</a> </body> </html>


In this example, I use a for loop to iterate over the gossips passed to the template, and for

each gossip, I display the gossip as a list item. The {{ name }} and {{ gossip.gossip }} are

placeholders that are replaced by the actual data passed to the template.

You could add some CSS to format the gossips list and the website.

Please make sure that the gossips variable passed to the template is a list of gossips, and

each gossip has a gossip attribute

It's important to note that this is just one example, and you can customize and adjust the

HTML to suit your needs.

There is a problem in gossips.html. The link in the return button doesn't work.
You're correct, my apologies for the oversight. In the gossips.html file, the <a

href="index.html">Return</a> link that I provided is a relative link, which means it's relative to the

current location of the gossips.html file. Since the gossips.html file is located in the

templates folder, you should use the full path to the index.html file.

Here's an example of how you can modify the gossips.html file to fix the link:

Copy code

<a href="{{ url_for('index') }}">Return</a>

In this example, I use the url_for() function provided by Flask, which generates the URL for a

given endpoint. The 'index' argument is the name of the endpoint that handles the index page.

Alternatively, if you know the full path to the index.html file, you can use that instead.

Also please make sure that you have the same name in the route decorator and the url_for

function in the gossips.html file.


Where is the name of the endpoint in the python file?
In the python file, the name of the endpoint is the name of the function that handles the
request.
For example, in the script I provided earlier, the endpoint for the index page is the index()

function, so the name of the endpoint is 'index'.

Copy code

@app.route('/', methods=['GET']) def index(): return render_template('index.html')

The @app.route() decorator is used to define the endpoint and the URL path that maps to it, in

this case, the endpoint is index() and the URL path is '/'(root), so when the user navigates to

the root of your website, the index() function will handle the request and return the index.html

template

You can also give a name to the endpoint by providing a string as the first argument of the

app.route() decorator, like this:

Copy code

@app.route('/', methods=['GET'], endpoint='index') def index_page(): return render_template('index.html')

In this case, the name of the endpoint is 'index' and the function handling the request is
index_page()

You might also like