215๐
You need to install django rest framework using pip3 (pip for python 3):
pip3 install djangorestframework
Instructions on how to install pip3 can be found here
78๐
if you forget ,
,this will happen,itโs weird
wrong example: need a ,
INSTALLED_APPS = [
'rest_framework'
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
- [Django]-"{% extends %}" and "{% include %}" in Django Templates
- [Django]-Django connection to PostgreSQL: "Peer authentication failed"
- [Django]-How can I create a deep clone of a DB object in Django?
23๐
Also, check for the possibility of a tiny typo:
Itโs rest_framework
with an underscore (_
) in between!
Took me a while to figure out that I was using a dash insteadโฆ ๐
- [Django]-Django.db.utils.ProgrammingError: relation "bot_trade" does not exist
- [Django]-Django Sitemaps and "normal" views
- [Django]-Django error when installing Graphite โ settings.DATABASES is improperly configured. Please supply the ENGINE value
8๐
If youโre using some sort of virtual environment do this!
-
Exit from your virtual environment.
-
Activate your virtual environment.
After youโve done this you can try running your command again and this time it probably wonโt have any ImportErrors.
- [Django]-Django dynamic model fields
- [Django]-What's the idiomatic Python equivalent to Django's 'regroup' template tag?
- [Django]-How to set the timezone in Django
6๐
if after installing and adding it to your INSTALLED_APPS it persist, then itโs most likely because youโre using python3
to run the server and thats okay. So what you do while installing is use python3 -m pip install djangorestframework
.
- [Django]-How do I import the Django DoesNotExist exception?
- [Django]-What is the Simplest Possible Payment Gateway to Implement? (using Django)
- [Django]-How do you use the django-filter package with a list of parameters?
4๐
Maybe you install DRF is for python2, not for python3.
You can use python console
to check your module:
import rest_framework
Actually you use pip
to install module, it will install python2 module.
You should install the pip for python3:
sudo apt-get install python3-setuptools
sudo easy_install3 pip
So, you can install python3 module.
- [Django]-Django.contrib.auth.logout in Django
- [Django]-Creating a JSON response using Django and Python
- [Django]-Django: Display Choice Value
- [Django]-Django model CharField: max_length does not work?
- [Django]-405 "Method POST is not allowed" in Django REST framework
- [Django]-Django โ Circular model import issue
2๐
When using a virtual environment like virtualenv
without having django-rest-framework installed globally you might as well have the error.
The solution would be:
-
activate the environment first with
{{your environment name}}/bin/activate
for Linux or{{your environment name}}/Scripts/activate
for Windows -
and then run the command again.
- [Django]-Parsing unicode input using python json.loads
- [Django]-Warning: Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'
- [Django]-Django 2.0 โ Not a valid view function or pattern name (Customizing Auth views)
2๐
If you are working with PyCharm, I found that restarting the program and closing all prompts after adding โrest_frameworkโ to my INSTALLED_APPS
worked for me.
- [Django]-How to repeat a "block" in a django template
- [Django]-Separation of business logic and data access in django
- [Django]-What does error mean? : "Forbidden (Referer checking failed โ no Referer.):"
2๐
Yeh for me it was the python version as well โฆ
much better to use pipenv โฆ
create a virtual env using using python 3 โฆ
install pipenv : pip3 install pipenv
create the virtualenv: pipenv --python 3
activate the virtual env: pipenv shell
- [Django]-How to mix queryset results?
- [Django]-Get user profile in django
- [Django]-What is the difference between null=True and blank=True in Django?
2๐
INSTALLED_APPS = [
'rest_framework',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#apps
'apps.endpoints',
]
maybe forgot the comma "," or while pasting packing name it might have extra whitespace "packagename "check for that
- [Django]-How do I deploy Django on AWS?
- [Django]-Can I access constants in settings.py from templates in Django?
- [Django]-Django admin default filter
2๐
Also, if youโre getting this error while running docker-compose up
. Make sure to run docker-compose up --build
because docker needs to install the djangorestframework dependency as well.
- [Django]-ValueError: The field admin.LogEntry.user was declared with a lazy reference
- [Django]-Render HTML to PDF in Django site
- [Django]-How to customize activate_url on django-allauth?
2๐
I have faced the same issue and And solve it with upgrading the pip and install rest_framework after that.(update everything)
Windows Command Prompt
> python -m pip install --upgrade pip
Linux Terminal
$ pip install --upgrade pip
MacOS Terminal
$ pip install --upgrade pip
Install Django and Django REST framework
pip install django
pip install djangorestframework
- [Django]-How to stop autopep8 not installed messages in Code
- [Django]-Getting Django admin url for an object
- [Django]-Create empty queryset by default in django form fields
1๐
if you used pipenv:
if you installed rest_framework thru the new pipenv,
you need to run it thru the virtual environment:
1.pipenv shell
2.(env) now, run your command(for example python manage.py runserver)
- [Django]-How to duplicate virtualenv
- [Django]-How to serve media files on Django production environment?
- [Django]-The QuerySet value for an exact lookup must be limited to one result using slicing. Filter error
1๐
First installing the framework globally on the system solved my problem.
machine@debian:/$ sudo pip install djangorestframework
or;
root@debian:/# pip install djangorestframework
- [Django]-Where to put business logic in django
- [Django]-Do I need Nginx with Gunicorn if I am not serving any static content?
- [Django]-Checking for empty queryset in Django
1๐
(I would assume that folks using containers know what theyโre doing, but hereโs my two cents)
Letโs say you setup your project using cookiecutter-django and enabled the docker container support, be sure to update the pip requirements file with djangorestframework==<x.yy.z>
(or whichever python dependency youโre trying to install) and re-build the docker images (local and production).
- [Django]-Numeric for loop in Django templates
- [Django]-Django: Example of generic relations using the contenttypes framework?
- [Django]-Django composite unique on multiple model fields
1๐
Iโve faced the same problem, followed these instructions and it worked for me:
python -m pip install --upgrade pip
(to upgrade pip)pip3 install djangorestframework
-
Added
rest_framework
as first app:INSTALLED_APPS = [ 'rest_framework', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', #apps 'apps.endpoints', ]
- [Django]-How can I change the default Django date template format?
- [Django]-Differences between STATICFILES_DIR, STATIC_ROOT and MEDIA_ROOT
- [Django]-Django: Multiple forms possible when using FormView?
1๐
Install the missing module separately using pip installer
pip3 install djangorestframework-jsonapi
This worked for me.
- [Django]-Django ignores router when running tests?
- [Django]-ModuleNotFoundError: No module named 'grp' on windows
- [Django]-Django REST framework: non-model serializer
1๐
After installing the necessary packages with python3/pip3 inside my virtual environment, it all came down to running my server with python manage.py runserver
instead of python3 manage.py runserver
. This was because the virtual environment and other packages were installed using python3/pip3 and not python2/pip2, hence running the server with python3 again resulted in the error. Am sure this will help someone else.
- [Django]-Referencing multiple submit buttons in django
- [Django]-Django form: what is the best way to modify posted data before validating?
- [Django]-Malformed Packet: Django admin nested form can't submit, connection was reset
- [Django]-How to unit test file upload in django
- [Django]-What's the difference between `from django.conf import settings` and `import settings` in a Django project
- [Django]-Data Mining in a Django/Postgres application
0๐
In my case, my problem was different. I was creating in my bash_profile an alias like:
alias python=/usr/local/bin/python3
And even if I activate my environment, when I ran the command, the python interpreter accessed was from the system and not from my environment.
I just removed the alias from bash_profile and it worked fine.
- [Django]-Django model one foreign key to many tables
- [Django]-Auto-create primary key used when not defining a primary key type warning in Django
- [Django]-Django middleware difference between process_request and process_view
0๐
I know there is an accepted answer for this question and many other answers also but I just wanted to add an another case which happened with me was Updating the django and django rest framework to the latest versions to make them work properly without any error.
So all you have to do is just uninstall both django and django rest framework using:
pip uninstall django
pip uninstall djangorestframework
and then install it again using:
pip install django
pip install djangorestframework
- [Django]-How to completely uninstall a Django app?
- [Django]-STATIC_ROOT vs STATIC_URL in Django
- [Django]-How to completely dump the data for Django-CMS
0๐
I recently installed the latest Django 3.1 and Django Rest Framework 3.11.1 libraries only to eventually realize Django 3.1 is not supported by DRF as of 11 April 2020. I did not realize that the exact releases mentioned need to be used.
If youโre pulling your hair out because you canโt understand why DRF is not importing check these requirements and make sure your app is compatible.
- [Django]-Django simple_tag and setting context variables
- [Django]-Django :How to integrate Django Rest framework in an existing application?
- [Django]-Auto-create primary key used when not defining a primary key type warning in Django
0๐
In my case, I had installed it in the virtualenv but forgot to activate the virtualenv while running the command
python3 manage.py makemigrations
So in my case I had to just activate the environment and then run the command
source [virtualenv folder-name]/bin/activate
python3 manage.py makemigrations
This solved my problem.
- [Django]-Django โ Render the <label> of a single form field
- [Django]-Data Mining in a Django/Postgres application
- [Django]-Django TemplateSyntaxError โ 'staticfiles' is not a registered tag library
0๐
I face the same problem. In my case, I solved it by update Windows Defender configuration.
- [Django]-Django template includes slow?
- [Django]-Name '_' is not defined
- [Django]-How to implement followers/following in Django
0๐
activate the whole virtual environment
cd django_apps
source /root/django-apps/env/bin/activate
- [Django]-Difference between User.objects.create_user() vs User.objects.create() vs User().save() in django
- [Django]-Django 2 โ How to register a user using email confirmation and CBVs?
- [Django]-Django Queryset with year(date) = '2010'
0๐
Install pip3 install djangorestframework first
and add rest_framework in the settings.py.
This is how I have a shout out the problem.
- [Django]-Django 1.7 โ App 'your_app_name' does not have migrations
- [Django]-How to access Enum types in Django templates
- [Django]-Django 1.3.1 compilemessages. Error: sh: msgfmt: command not found
0๐
Make sure you are using the same language interpreter which you have used in your Django project, which can be an interpreter in the virtual environment, or like me, I have a normal python installed and an anaconda python too. So, try switching the interpreter.
See this image for reference
- [Django]-How can I get all the request headers in Django?
- [Django]-Github issues api 401, why? (django)
- [Django]-Django: Use of DATE_FORMAT, DATETIME_FORMAT, TIME_FORMAT in settings.py?
-1๐
On Windows, with PowerShell, I had to close and reopen the console and then reactive the virtual environment.
- [Django]-How to use refresh token to obtain new access token on django-oauth-toolkit?
- [Django]-Django Rest Framework โ Updating a foreign key
- [Django]-POST jQuery array to Django
-1๐
To install it, do the following:
pip install djangorestframework
pip install markdown
pip install django-filter
We have to check for a few common mistakes:
-
check comma at installed list elements
-
typo errors
- [Django]-Get list item dynamically in django templates
- [Django]-Django Cache cache.set Not storing data
- [Django]-Django ManyToMany filter()
-2๐
Try pressing the icon given if you are getting the following error:
โModuleNotFoundError: No module named โrest_framework'โ
It will ask you to import the given package, that is rest_framework
and run the code again.
This worked for me and trying to solve that error for a couple of days.
- [Django]-Passing STATIC_URL to file javascript with django
- [Django]-How to pass information using an HTTP redirect (in Django)
- [Django]-How to add superuser in Django from fixture