This is our second article in Django, in this article we are going to learn about Django Apps & URL Routing Example, Django Apps are one of the best features that you can use. also we are going to create our URL Routing Example in Django. in the first article we had a simple introduction in Django and also we have created our first project in Django, you can read that article in the below link.
Flask Web Development Tutorials
1: Flask CRUD Application with SQLAlchemy
2: Flask Creating News Web Application
3: Flask Creating REST API with Marshmallow
Python GUI Development Tutorials
1: PyQt5 GUI Development Tutorials
2: Pyside2 GUI Development Tutorials
3: wxPython GUI Development Tutorials
4: Kivy GUI Development Tutorials
5: TKinter GUI Development Tutorials
What are Django Apps?
Django apps are used to group application functionality. If you want to work with content from a database or user interactions you have to create and configure Django apps. a project can contain as many apps as you need. for example, if you have a project for a news website , you can create an app for sport news, another app for local news, another app for about information, another app for contact information , and create additional apps as they’re needed. There’s no hard rule to the number of apps in a project. Whether to make code management simpler or delegate app work to a team, the purpose of Django apps is to group application functionality to make work easier. Django apps are normally contained in sub directories inside a project. This approach makes it easier to use Python references and naming conventions. If the project name is NewsWebsite, the functionality of an app named contact is easily referred through Python packages as newswebsite.contact. Because apps provide a modular way to group application functionality, it’s common for other people or groups to distribute Django apps with popular functionality. For example, if a Django project requires forum functionality, instead of writing a forum app from scratch, you can leverage one of several Django forum apps. The more general purpose the functionality you’re looking for, the more likely you’ll be able to find a Django app created by a third party.
OK first of all you need to create a Django Project, iam going to call it MyProject,
after that you need to change directory to your project like this.
1 2 |
django-admin startproject MyProject cd MyProject |
To complete the project setup, we will need to create the tables in the database required by the applications listed in INSTALLED_APPS. Open the shell and run the following commands:
1 2 |
cd MyProject python manage.py migrate |
Now it’s time to create our app, for example iam going to call my app as contact, but you can name what you want. you can create the app in django by using this command, make sure that you have changed the directory to your project.
1 |
python manage.py startapp contact |
a subdirectory named contact is created containing the app. By default, upon creating an app its subdirectory includes the following:
- __init__.py .- Python file to allow app packages to be imported from other
directories. Note __init__.py is not a Django specific file, it’s a generic file used in
almost all Python applications. - migrations.- Directory that contains migrations applied to the app’s database
definitions (i.e., model classes). - admin.py .- File with admin definitions for the app – such definitions are needed to
access model class instances from the Django admin. - apps.py .- File with configuration parameters for the app.
- models.py .- File with database definitions (i.e., model classes) for the app.
- tests.py .- File with test definitions for the app.
Subscribe and Get Free Video Courses & Articles in your Email