Building a Simple Django App


  • Python
  • Django
    • 1
    • IN
    • Verified
    • Posted byPraveen
    • TimeSept. 4, 2024, 6:55 p.m.
    • StatusActive

    Snippet Description

    Create a new Django app: This generates the necessary files for your app. Create a view: This defines a function that handles requests and returns a response. Create a template: This defines the HTML structure of your page. Update urls.py: This maps URLs to views in your project. To run this app: Start the development server: python manage.py runserver Open your web browser and go to http://127.0.0.1:8000/ You should see the message "Hello, World!" displayed on your page..

    Code

      # Create a new Django app
      python manage.py startapp myapp

      # Create a view in myapp/views.py
      from django.shortcuts import render

      def index(request):
          context = {'name': 'World'}
          return render(request, 'myapp/index.html', context)

      # Create a template in myapp/templates/myapp/index.html
      <!DOCTYPE html>
      <html>
      <head>
          <title>Hello, World!</title>
      </head>
      <body>
          <h1>Hello, {{ name }}!</h1>
      </body>
      </html>

    Comments

    Related Posts

    Send SMS using Django-Python

    Python Django

    3 Aug. 14, 2022, 4:32 p.m.
    Proud

    Nginx 502 Bad Gateway - Django

    Nginx Python Django

    13 March 17, 2022, 3:34 p.m.
    Proud

    Django Project Updating on Server

    Nginx Python Django

    14 March 17, 2022, 2:17 p.m.
    Proud

    Want to Hire our experts?

    We'll help you to grow your career and growth.
    SignUp Today