- We continuous previous post Configure the basic setup initialization in a new Django project
- Now create a urls.py file in "app" folder which is a django app.
- Now go to myproj's urls.py file and write this.
    from django.contrib import admin
    from django.urls import path, include
    urlpatterns = [
        path('admin/', admin.site.urls),
        path("app/", include("app.urls"))
    ]
- Now go to app's urls.py file and paste this code.
    from django.urls import path
    from . import views
    urlpatterns = [
        path("home", views.handleHome, name="home")
    ]
- Now go to app's views.py file and paste this code.
    from django.shortcuts import render
    def handleHome(request):
        return render(request, "index.html")
- Now go to templates folder which is exist in root directory and create a file index.html inside templates folder and paste this code.
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <h1>hello world</h1>
    </body>
    </html>
- After all of these setups, your project's tree view will look like this in VS Code:
- Now run this command in VS Code's terminal:
    python manage.py runserver
- Congrats!!! your project is running with http://127.0.0.1:8000/
- That's it.


No comments:
Post a Comment