← Back to Django Course | Chapter 14: REST API with DRF | Lesson 2 of 6

Django REST Framework Install करना

एक JSON API बनाने से पहले, आप djangorestframework package install करते हैं और Django को इसे उपयोग करने के लिए बताते हैं।

Package Install करना

अपने virtual environment को active रखते हुए, pip उपयोग करके DRF install करें, वैसे ही जैसे आपने खुद Django install किया था।

Note: इसे अपने project के root folder से, virtual environment activated के साथ run करें।

उदाहरण: Installing the Package

With your virtual environment active, install DRF using pip, the same way you installed Django itself.

bash
pip install djangorestframework

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

App को Register करना

किसी भी Django app की तरह, DRF को INSTALLED_APPS में listed होना चाहिए ताकि Django इसके templates, static files, और features (जैसे browsable API) load करे।

उदाहरण: Registering the App

Like any Django app, DRF must be listed in INSTALLED_APPS so Django loads its templates, static files, and features (like the browsable API).

markup
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'myapp',
]
{# 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. #}

Install को Verify करना

अपने virtual environment के अंदर Python interpreter से इसका version confirm करके जांचें कि DRF सही से install हुआ।

उदाहरण: Verifying the Install

Check that DRF installed correctly by confirming its version from the Python interpreter inside your virtual environment.

bash
python -c "import rest_framework; print(rest_framework.VERSION)"

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

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. djangorestframework install करना लेकिन INSTALLED_APPS में rest_framework add करना भूल जाना, इसलिए DRF की features silently activate नहीं होती।
  2. इसे project के virtual environment के अंदर उपयोग करने के बजाय globally install करना, जो machines के बीच version mismatches का कारण बनता है।
  3. settings.py में rest_framework add करने के बाद development server restart न करना।
चैप्टर सारांश
  • pip install djangorestframework से DRF को अपने active virtual environment में install करें।
  • settings.py में INSTALLED_APPS list में rest_framework add करें।
  • Development server restart करें ताकि नया app pick up हो जाए।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

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.