Django App बनाना
In this page:
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।
उदाहरण: 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.
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.
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.
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. #}
- startapp को project की root directory के बाहर से run करना, जो app folder को गलत जगह बनाता है।
- एक app को built-in Python module (जैसे test या json) जैसा ही नाम देना, जो import conflicts का कारण बनता है।
- नए बनाए 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 करे।
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: