
Django App Structure & syntax
After running startapp command, we'll see bunch of files in the app. Such as:
__init__.py-> it turns our app folder into a proper python package. Django expects apps to be proper packages, not just files. having __init__.py ensures the app behaves like a package.
it helps Django discover the app when added it to the INSTALLES_APPS in settings.py
admin.py->it is used for registering models in Django's admin panel.
admin.site.register(Profile)
apps.py-> used to configure app settings.
class AccountsConfig(AppConfig):
name = 'accounts'
models.py-> defines database tables
class Profile(models.Model):
user=....
about=...
def__str__(self):
return self.user.usernametests.py->it contains unit tests.
urls.py-> we need to create this as a file(if not exists) and connect this url path to the mother app. This file routes requests to views
urlpatterns=[
path('accounts/' views.home, name='home'),
]
views.py->handles function's logic and connects with the templates.
def home(request):
return render(request, 'landingpages/index.html')

Join Techsnap Creators
Share your knowledge and earn ??
Want to showcase your tech expertise and get rewarded for your insights? Join the Techsnap creator network!
Write insightful blogs, stay ahead of industry trends, and grow your professional brand while helping others in the community.
Ready to make an impact?

Comments