Creating an About Us Web page in Python Django – Be on the Proper Facet of Change

Advertisements

[ad_1]

Normal Answer

Creating an “About Us” web page in Django includes optionally creating a brand new app, after which defining a view to render the web page. You then create a URL for the view and an HTML template for the web page content material. Lastly, you run the server to view your “About Us” web page.

Step 1: Create a New Django App (Optionally available)

If you wish to maintain your mission organized, you possibly can create a brand new app in your “About Us” web page. In your terminal, navigate to your Django mission listing and run the next command: python handle.py startapp about.

Step 2: Add the App to Your Mission Settings (If a New App is Created)

Open your Django mission’s settings file (normally settings.py) and add your new app to the INSTALLED_APPS listing.

Step 3: Create a View for the Web page

Within the views.py file of your app, create a view in your web page:

from django.shortcuts import render

def about_view(request):
    return render(request, 'about/about.html')

This view will render the “About Us” web page when the web page is visited.

Step 4: Create a URL for the View

Within the urls.py file of your app, create a URL in your view:

from django.urls import path
from .views import about_view

urlpatterns = [
    path('about/', about_view, name="about"),
]

Step 5: Create a Template for the Web page

In your app’s templates listing (you would possibly have to create it), create a brand new listing named ‘about‘ and inside it, create an HTML file: about.html. This file ought to comprise the HTML in your “About Us” web page.

Step 6: Run the Server

Lastly, run your server with python handle.py runserver and go to http://localhost:8000/about/ to see your “About Us” web page.

Keep in mind to switch ‘about’ with the precise identify of your app if it’s totally different. This can be a very fundamental instance. In a real-world utility, you would possibly wish to add extra options, like dynamic content material, photographs, and so on.

Instance

The ‘About’ or ‘About Us’ web page incorporates details about the aim and targets of your weblog. It must also embrace your background and experience within the chosen area of interest and different related data to assist readers perceive your weblog.

Let’s create the about.html template.

{% extends 'base.html' %}
{% block content material %}

<div class="container">
  <div class="row">
    <div class="col-md-8 card mb-4  mt-3 left  high">
      <div class="card-body">
          <h1>About Us</h1>
          <p class="card-text">I created this weblog to share ideas, strategies and sensible recommendation on find out how to preserve good well being</p>
          <p class="card-text">I am not a well being professional however I'm passionate concerning the subject and dedicated to offering correct and dependable data.</p>
          <p class="card-text">Any suggestion is extremely welcome. Be happy to <a href="https://weblog.finxter.com/creating-an-about-us-page-in-python-django/{% url"contact' %}">contact me</a> for extra data or to say hey.</p>
      </div>
    </div>
  </div>
</div>
{% endblock %}

As typical, we lengthen the bottom template. Contained in the block, we write what our weblog is all about. Discover how we hyperlink the contact web page utilizing Django template engine’s {% url … %} tag. Inside it, we use the goal identify we specified earlier within the urls.py file.

We wish this ‘About’ web page to look on each submit. So, we’ll embrace it on the footer of the bottom template.

<footer class="py-3 bg-grey">
            <p class="m-0 text-dark text-center ">Copyright &copy; Django Weblog</p>
            <p class="m-0 text-dark text-center"><a href="https://weblog.finxter.com/creating-an-about-us-page-in-python-django/{% url"about' %}">About Us</a></p>
  </footer>

So, from the About web page, we are able to see a hyperlink to the contact web page. You’ll be able to as properly add a hyperlink to your social media pages. For the view perform, it’s fairly easy.

def about(request):
    return render(request, 'about.html')

Then, the endpoint:

path('about', about, identify="about"),

Try the GitHub repository for the complete code of my portfolio app and the start of my tutorial sequence for those who haven’t already:

?‍? Really helpful: Python Django Portfolio App – How I Made It


[ad_2]