Practical Django Applications and Multiple Applications
Practical Django Applications and Multiple Applications
In the previous video we created our first Django Application and displayed
“Hello World!” on the web page.
In this video we are going to see more Django basic applications practical.
Example 1-
Multiple Views for greetings (Good morning, Good afternoon, Good Evening)
Step 1: create a project named secondproject
HT EASY LEARNING
HT EASY LEARNING
HT EASY LEARNING
HT EASY LEARNING
Always remember whenever we create a new app the first step to do is to add it in
INSTALLED_APPS list in the settings.py file.
HT EASY LEARNING
HT EASY LEARNING
Line 7 uses the datetime.datetime.now() function to get the current date and
time. This function retrieves the current date and time from the server's system
clock.
Step 3: Define URL pattern for datetime view in urls.py-
Here we have to give v2 name for views of timeapp because of the conflict
between names of views which will raise an error. We can use the above approach
to solve this problem or we can also define urlpattern like this-
HT EASY LEARNING
HT EASY LEARNING
HT EASY LEARNING
HT EASY LEARNING
simply define the URLs at the application level and include that file in the project
level URLs.
Independent Development: Developers can work on app-specific URLs without
affecting the overall project URL structure. This simplifies development and testing
processes.
Easier Updates: As your application grows, adding or modifying URLs within an
app is more straightforward as you only need to update the app's urls.py file.
Example-
1.Create a new project and create a application-
HT EASY LEARNING
HT EASY LEARNING
HT EASY LEARNING
HT EASY LEARNING
Main advantages-
The main advantages of defining urlpatterns at application level instead of project
level are:
1) It promotes reusability of Django Applications across multiple projects
2) Project level urls.py file will be clean and more readable
HT EASY LEARNING
HT EASY LEARNING
HT EASY LEARNING