Hands-On Django part-2(create app in Django project)
Django is famous for its unique app structure. you can create your application inside the project by each feature which is easy to manage.
Before we start you need to have a virtual environment and Django installed with the project created in that.
If you have not yet created project please refer PART-1
If you are ready with the project then let’s get started
This will be your project structure if you have created it. now let’s quickly move to create an app in your project.
To create app type following command -
python manage.py startapp projectApp
Now you will see one app created inside your project
Now after creating an app you need to add your app to your project in order to consider the app in your project.
let’s take a quick look at how you can do that.
Add project to settings by adding the name of your project
Now we finally included our app to project, now in order to render the app using url you need to include the app in your main app so that the urls can be redirected to the app.
Move to projectName-> projectName -> urls.py
and add below code in the header
from django.urls import include
now let's add path to your app from urls.py
from django.contrib import adminfrom django.urls import pathfrom django.urls import includeurlpatterns = [path('admin/', admin.site.urls),path('', include("projectApp.urls")),]
Now you can use default MVT structure and your app URLs will be automatically added to the path.
In Next we will see how to create models in Django.
Thanks for your time.