In Django, every functionality of the webpage is separated into apps. (e.g., authentication, checkout, payment and etc.)
So a project would be the combination of such apps in one website.
To create a Django app:
python manage.py startapp appname
Ensure you are in the same dir where the manage.py file is located!
This command created the app folder.
First of all, your application has to respond to requests a user makes. To do so, you should create a basic function in Views.py.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world")
Django applications have to know the route of the URLs inside the app. So you have to generate the urls.py file inside the application folder.
In urls.py, you have to write the following code:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
Now your app knows that if the user requests the index webpage, it should respond with the function in the views.py file.
Each application in the project would have its own urls.py configuration file. So to "Plug" this file into your project-level urls.py configuration file, you have to include the app's urls.py in the project urls.py, like so:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('helloworldapp/', inclue('helloworldapp.urls')),
path('admin/', admin.site.urls),
]
now, if you run the server and navigate into:
localhost:8000/your-app-name
You should be able to see the response of your basic application!