← Back to Django Course | Chapter 2: Apps, URLs & Views | Lesson 2 of 10

Django App बनाना

startapp command Django से कहता है कि सही folders और files पहले से label किए हुए एक empty toy box बना दे।
Syntax
markup
python manage.py startapp app_name

startapp Run करना

manage.py वाली directory से, python manage.py startapp <app_name> run करें। Django standard app layout के साथ एक नया folder generate करता है: models.py, views.py, admin.py, apps.py, और एक migrations package।

Note: Short, lowercase, singular app names उपयोग करें जैसे blog या accounts — वे Python import paths का हिस्सा बन जाते हैं।

उदाहरण: Running startapp

From the directory containing manage.py, run python manage.py startapp <app_name>. Django generates a new folder with the standard app layout: models.py, views.py, admin.py, apps.py, and a migrations package.

bash
python manage.py startapp blog

⚠️ Run this in your own terminal or Node.js environment.

Generated Files Inspect करना

startapp run होने के बाद, exactly यह देखने के लिए नया folder list करें कि Django ने क्या बनाया। हर file में already minimal boilerplate होता है ताकि आपको पता हो अपना code कहां जोड़ना है।

उदाहरण: Inspecting the Generated Files

After startapp runs, list the new folder to see exactly what Django created. Each file already has minimal boilerplate so you know where to add your own code.

bash
ls blog/
# admin.py  apps.py  __init__.py  migrations/  models.py  tests.py  views.py

⚠️ Run this in your own terminal or Node.js environment.

apps.py Config File

startapp एक AppConfig subclass के साथ apps.py भी बनाता है। Django internally इस class को app identify करने के लिए उपयोग करता है, और इसका name attribute app के Python package path से match होना चाहिए।

उदाहरण: The apps.py Config File

startapp also creates apps.py with an AppConfig subclass. Django uses this class internally to identify the app, and its name attribute must match the app's Python package path.

markup
from django.apps import AppConfig

class BlogConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'blog'
{# Django-only code -- models.py/views.py/urls.py/settings.py snippets, or template markup using Django template tags/variables -- can't run standalone via Judge0 or the browser preview, since it needs a real Django project. Only this course's pure-Python examples (example_lang == 'python', no Django imports) are actually runnable, so those still get the button below. #}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. startapp को project की root directory के बाहर से run करना, जो app folder को गलत जगह बनाता है।
  2. एक app को built-in Python module (जैसे test या json) जैसा ही नाम देना, जो import conflicts का कारण बनता है।
  3. नए बनाए app को INSTALLED_APPS में जोड़ना भूल जाना, इसलिए Django इसके models या templates कभी load नहीं करता।
चैप्टर सारांश
  • python manage.py startapp <name> models.py, views.py, और बाकी के साथ एक नया app folder scaffold करता है।
  • startapp को manage.py जैसी ही directory से run करें ताकि app project root पर आए।
  • App बनाना सिर्फ step one है — इसे अब भी register करना होता है इससे पहले कि Django इसे recognize करे।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.