<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rex Steve on Medium]]></title>
        <description><![CDATA[Stories by Rex Steve on Medium]]></description>
        <link>https://medium.com/@RexSteve?source=rss-ca79d4ba7d42------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ALHpUXf6BYbj4jRDTbrAYQ.jpeg</url>
            <title>Stories by Rex Steve on Medium</title>
            <link>https://medium.com/@RexSteve?source=rss-ca79d4ba7d42------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:51:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@RexSteve/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Course 1: Introduction to Web Development and Flask]]></title>
            <link>https://medium.com/@RexSteve/course-1-introduction-to-web-development-and-flask-f9708e557fac?source=rss-ca79d4ba7d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9708e557fac</guid>
            <dc:creator><![CDATA[Rex Steve]]></dc:creator>
            <pubDate>Mon, 13 Nov 2023 15:22:30 GMT</pubDate>
            <atom:updated>2023-11-14T20:02:19.610Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*cxxUjSB3vKDYzOQou5Sy4w.png" /></figure><h3>1. Introduction</h3><p>Welcome to the world of web development with Flask! In this tutorial, I’ll guide you through the process of building a basic Flask application. Flask is a lightweight and flexible web framework for Python, making it an excellent choice for both beginners and experienced developers.</p><h3>Prerequisites</h3><p>Before we get started, make sure you have Python installed on your machine. You can download Python from the official website: <a href="https://www.python.org/downloads/">Python Downloads</a></p><h3>2. Setting Up Your Flask Environment</h3><h4>2.1 Installing Flask</h4><p>Set up a virtual environment and install Flask:</p><pre>python -m venv venv<br>source venv/bin/activate  # On Windows, use `venv\Scripts\activate`<br>pip install Flask</pre><h4>2.2 Creating Your First Flask App</h4><p>Create a simple Flask app:<br>Create a new file named app.py in your project folder. Open it in your preferred code editor and add the following code:</p><pre>from flask import Flask<br><br>app = Flask(__name__)<br><br>@app.route(&#39;/&#39;)<br>def home():<br>    return &#39;Hello, Flask!&#39;<br><br>if __name__ == &#39;__main__&#39;:<br>    app.run(debug=True)</pre><p><em>In this code:</em></p><ul><li><em>We import the </em><em>Flask class from the </em><em>flask module.</em></li><li><em>We create an instance of the </em><em>Flask class called </em><em>app.</em></li><li><em>We define a route using the </em><em>@app.route(&#39;/&#39;) decorator. This means when someone accesses the root URL (&quot;/&quot;), the </em><em>hello() function will be executed.</em></li><li><em>The </em><em>home() function simply returns the string &#39;Hello, Flask!&#39;</em></li></ul><h3>3. Routing and Views</h3><h4>3.1 Basic Routing</h4><p>Define routes for different parts of your application:</p><pre>@app.route(&#39;/&#39;)<br>def home():<br>    return &#39;Home Page&#39;<br><br>@app.route(&#39;/about&#39;)<br>def about():<br>    return &#39;About Page&#39;</pre><h4>3.2 Dynamic Routing</h4><p>Handle dynamic URL parameters:</p><pre>@app.route(&#39;/user/&lt;username&gt;&#39;)<br>def show_user(username):<br>    return f&#39;User: {username}&#39;</pre><h3>4. Templates and Static Files</h3><h4>4.1 Using Templates</h4><p>Render HTML templates with Flask’s Jinja2:<br>Flask uses the Jinja2 templating engine to render dynamic content in HTML files. Let’s create a simple template.</p><p><strong>Project Structure</strong><br>Your project structure should now look like this:</p><pre>my_flask_project/<br>│   app.py<br>└───templates/<br>    └───index.html<br>    └───profile.html</pre><p><strong>Creating an HTML Template<br></strong>Create a new file named index.html inside the templates folder:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;Flask Tutorial&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;{{ message }}&lt;/h1&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><em>In this template, </em><em>{{ message }} is a placeholder that we&#39;ll replace with dynamic content.</em></p><h4>4.2 Modifying Your Flask App</h4><p>Update your app.py file:</p><pre>from flask import render_template<br><br>@app.route(&#39;/profile/&lt;username&gt;&#39;)<br>def profile(username):<br>    return render_template(&#39;profile.html&#39;, username=username)</pre><p><em>Here, we’ve imported </em><em>render_template and modified the </em><em>profile() function to render the </em><em>profile.html template with a dynamic message.</em></p><h4>4.3 Serving Static Files</h4><p>Serve static files like CSS and images:</p><pre># Place static files in the &#39;static&#39; folder<br># Access them in templates using url_for(&#39;static&#39;, filename=&#39;...&#39;)</pre><h3>5. Forms and User Input</h3><h4>5.1 Building Forms</h4><p>Create HTML forms and handle form submissions:</p><pre>from flask import render_template, request<br><br>@app.route(&#39;/login&#39;, methods=[&#39;GET&#39;, &#39;POST&#39;])<br>def login():<br>    if request.method == &#39;POST&#39;:<br>        username = request.form[&#39;username&#39;]<br>        password = request.form[&#39;password&#39;]<br>        # Validate and authenticate user<br>    return render_template(&#39;login.html&#39;)</pre><h4>5.2 Form Validation with WTForms</h4><p>Use the WTForms library for form validation:</p><pre>pip install Flask-WTF</pre><pre>from flask_wtf import FlaskForm<br>from wtforms import StringField, PasswordField<br>from wtforms.validators import InputRequired<br><br>class LoginForm(FlaskForm):<br>    username = StringField(&#39;Username&#39;, validators=[InputRequired()])<br>    password = PasswordField(&#39;Password&#39;, validators=[InputRequired()])</pre><h3>6. Database Integration with SQLAlchemy</h3><h4>6.1 Setting Up SQLAlchemy</h4><p>Integrate Flask with the SQLAlchemy ORM:</p><pre>pip install Flask-SQLAlchemy</pre><pre>from flask_sqlalchemy import SQLAlchemy<br><br>app.config[&#39;SQLALCHEMY_DATABASE_URI&#39;] = &#39;sqlite:///site.db&#39;<br>db = SQLAlchemy(app)</pre><h4>6.2 Creating Models and Database Tables</h4><p>Define models and create database tables:</p><pre>class User(db.Model):<br>    id = db.Column(db.Integer, primary_key=True)<br>    username = db.Column(db.String(80), unique=True, nullable=False)<br>    email = db.Column(db.String(120), unique=True, nullable=False)</pre><h3>7. User Authentication and Authorization</h3><h4>7.1 Flask-Login for User Sessions</h4><p>Manage user sessions with Flask-Login:</p><pre>pip install Flask-Login</pre><pre>from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user<br><br>login_manager = LoginManager(app)<br>login_manager.login_view = &#39;login&#39;<br><br>class User(UserMixin, db.Model):<br>    # Existing User model<br><br>@login_manager.user_loader<br>def load_user(user_id):<br>    return User.query.get(int(user_id))</pre><h4>7.2 Securing Routes and Permissions</h4><p>Restrict access to routes based on user authentication:</p><pre>@app.route(&#39;/dashboard&#39;)<br>@login_required<br>def dashboard():<br>    return f&#39;Dashboard for {current_user.username}&#39;</pre><h3>8. RESTful APIs with Flask-RESTful</h3><h4>8.1 Introduction to RESTful APIs</h4><p>Understand the principles of RESTful APIs:</p><ul><li>Resources, endpoints, methods</li></ul><h4>8.2 Creating RESTful Endpoints with Flask-RESTful</h4><p>Build RESTful endpoints using Flask-RESTful:</p><pre>pip install Flask-RESTful</pre><pre>from flask_restful import Resource, Api<br><br>api = Api(app)<br><br>class HelloWorld(Resource):<br>    def get(self):<br>        return {&#39;hello&#39;: &#39;world&#39;}<br><br>api.add_resource(HelloWorld, &#39;/api/hello&#39;)</pre><h3>Advanced Features and Practices</h3><h4>Flask Blueprints for Modular Applications</h4><p>Organize your application with Flask Blueprints:</p><pre># auth.py (in a &#39;auth&#39; folder)<br>from flask import Blueprint<br><br>auth = Blueprint(&#39;auth&#39;, __name__)<br><br>@auth.route(&#39;/login&#39;)<br>def login():<br>    return &#39;Login Page&#39;</pre><pre># app.py<br>from flask import Flask<br>from auth import auth<br><br>app = Flask(__name__)<br>app.register_blueprint(auth, url_prefix=&#39;/auth&#39;)</pre><h4>GraphQL APIs with Graphene-Flask</h4><p>Implement a GraphQL API using Graphene-Flask:</p><pre>pip install graphene Flask-GraphQL</pre><pre>from flask_graphql import GraphQLView<br>from graphene import ObjectType, String, Schema<br><br>class Query(ObjectType):<br>    hello = String(name=String(default_value=&quot;World&quot;))<br><br>    def resolve_hello(root, info, name):<br>        return f&#39;Hello {name}&#39;<br><br>schema = Schema(query=Query)<br><br>app.add_url_rule(&#39;/graphql&#39;, view_func=GraphQLView.as_view(&#39;graphql&#39;, schema=schema, graphiql=True))</pre><h4><strong>Next Lessons: <br>Course 2: Database Management with SQLAlchemy</strong></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9708e557fac" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>