Git Product home page Git Product logo

simple-django-page's Introduction

simple-django-page

First, start a new Django project:

django-admin startproject myproject

This will create a new directory called "myproject" with the basic Django files. Next, create a new Django app:

python manage.py startapp myapp

This will create a new directory called "myapp" with the basic Django app files.

Next, open the file "myproject/settings.py" and add "myapp" to the list of installed apps:

INSTALLED_APPS = [    ...    'myapp',]

Next, create a new view in the file "myapp/views.py":

from django.shortcuts import render

def home(request):
    return render(request, 'myapp/home.html')

This view will use Django's render function to render a template called "home.html".

Next, create the template "myapp/templates/myapp/home.html":

<!doctype html>
<html>
  <head>
    <title>My 1st App</title>
    <style>
      h1 {
        color: #333;
        text-align: center;
        margin-top: 50px;
      }
      p {
        font-size: 18px;
        line-height: 1.6;
        width: 60%;
        margin: 0 auto;
        text-align: justify;
      }
    </style>
  </head>
  <body>
    <h1>My 1st App</h1>
    <p>Welcome to my first Django app! This is a simple page with a title and a paragraph of text. I've added some basic CSS styling to make the page look a little bit better. I hope you like it!</p>
  </body>
</html>

This template includes a title, some basic CSS styling, and a paragraph of text.

Next, create a new URL pattern in the file "myapp/urls.py":

from django.urls import path

from . import views

urlpatterns = [
    path('', views.home, name='home'),
]

This URL pattern will map the root URL of the app to the "home" view.

Finally, include the URL patterns of the app in the project's URL patterns in the file "myproject/urls.py":

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('myapp/', include('myapp.urls')),
    path('admin/', admin.site.urls),
]

Now you can start the development server and visit http://localhost:8000/myapp/ to see the page with the title "My 1st App" and the paragraph of text.

python manage.py runserver

I hope this helps! Let me know if you have any questions

simple-django-page's People

Contributors

gokul6350 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.