I am facing an issue of importing rest_framework inside my django app whenever i try to make migrations or create superuser or simply run the runserver.
I have installed the framework using this command but django still doesn't recognize it
sudo pip install djangorestframework
here's the snippet of settings.py file:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'companies.apps.CompaniesConfig',
]
REST_FRAMEWORK = {
'DEFAULT_MODEL_SERIALIZER_CLASS':
'rest_framework.serializers.HyperlinkedModelSerializer',
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}
Output:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/tam/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
/django/core/management/__init__.py", line 364
in execute_from_command_line utility.execute()
File "/home/tam/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/home/tam/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/tam/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/tam/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/home/tam/Canopy/appdata/canopy-1.7.4.3348.rh5-x86_64/lib/python2.7/
importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named rest_framework
Related
I'm using django 1.8 and satchmo project. But after successful installation of satchmo project when I try to start the server it's showing me this error
`Traceback (most recent call last):
File "manage.py", line 25, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 308, in execute
settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/Cellar/python#2/2.7.16_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named skeleton.settings`
INSTALLED_APPS = (
'django.contrib.sites',
'satchmo_store.shop',
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.auth',
'django.contrib.contenttypes',
#'django.contrib.comments',
'django.contrib.sessions',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'django.contrib.messages',
'django_comments',
'registration',
'sorl.thumbnail',
'keyedcache',
'livesettings',
'l10n',
'satchmo_utils.satchmo_thumbnail',
'satchmo_store.contact',
'tax',
'tax.modules.no',
'tax.modules.area',
'tax.modules.percent',
'shipping',
#'satchmo_store.contact.supplier',
#'shipping.modules.tiered',
#'satchmo_ext.newsletter',
#'satchmo_ext.recentlist',
'product',
'product.modules.configurable',
'product.modules.custom',
'product.modules.downloadable',
'product.modules.subscription',
#'satchmo_ext.product_feeds',
#'satchmo_ext.brand',
'payment',
'payment.modules.dummy',
#'payment.modules.purchaseorder',
#'payment.modules.giftcertificate',
#'satchmo_ext.wishlist',
#'satchmo_ext.upsell',
#'satchmo_ext.productratings',
'satchmo_ext.satchmo_toolbar',
'satchmo_utils',
#'shipping.modules.tieredquantity',
#'satchmo_ext.tieredpricing',
#'debug_toolbar',
'app_plugins',
'simple',
'store.localsite',
'skeleton',
)
Here I've added to installed apps. Still, it doesn't work. Can you tell me the use of the skeleton?
Also somehow skeleton doesn't compatible with django 1.8.
I'm trying to build my first web application using Django.
I'm actually referring to Using Python With Oracle Database 11g (under the section 'Using the Django Framework')
however while trying to execute the command python manage.py runserver i'm getting an error
Steps followed
django-admin.py startproject myproj
cd myproj
python manage.py startapp myapp
Once the above commands were executed successfully, the next step was to modify the connection settings to allow the application to connect to the database in the file myproj/settings.py.
Here i updated the details with our database details
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': '<our ebs database name>',
'USER': <username>,
'PASSWORD': <password>,
}
}
Also added the project under the INSTALLED_APPS to associate the application with the project:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myproj.myapp'
]
In a terminal window when i try to execute the below command from myproj directory:
python manage.py runserver
I'm getting the below error message
C:\Users\xxx\Desktop\Python files\myproj>python manage.py runserver
Unhandled exception in thread started by .wrapper at 0x00000274CA28AEA0>
Traceback (most recent call last):
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\config.py", line 118, in create
cls = getattr(mod, cls_name)
AttributeError: module 'myproj' has no attribute 'myapp'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\django__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\config.py", line 123, in create
import_module(entry)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\importlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'myproj.myapp'
I am a novice of Django.I think the problem is myproj.myapp. You don't need the project name, just add 'myapp', to INSTALLED_APPS.Hope it will be helpful.
From the "Writing your first Django app, part 2: Activating models" tutorial:
To include the app in our project, we need to add a reference to its configuration class in the INSTALLED_APPS setting. The PollsConfig class is in the polls/apps.py file, so its dotted path is 'polls.apps.PollsConfig'. Edit the mysite/settings.py file and add that dotted path to the INSTALLED_APPS setting. It’ll look like this:
mysite/settings.py¶
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
So look in myproj/apps.py and see what the name of the class is and your INSTALLED_APP should be something like:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myproj.apps.MyprojConfig'
]
I am buidling a chat app with WebSockets and django channels.
I run 'pip install channels' it gets installed successfully. Then I install 'asgi_redis'. That too gets installed. Now when I try to import channels.asgi it gives me error. Also suddenly my manage.py shell stops working. In other django projects it works fine.
Error when I try to access shell:
C:\Users\gdhameeja\Desktop\chatapp\chat>manage.py shell
Traceback (most recent call last):
File "C:\Users\gdhameeja\Desktop\chatapp\chat\manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\core\management\__init__.py", line 338, in execute
django.setup()
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\apps\registry.py", line 116, in populate
app_config.ready()
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\channels\apps.py", line 17, in ready
monkeypatch_django()
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\channels\hacks.py", line 10, in monkeypatch_django
from .management.commands.runserver import Command as RunserverCommand
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\channels\management\commands\runserver.py", line 5, in <module>
from daphne.server import Server, build_endpoint_description_strings
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\daphne\server.py", line 9, in <module>
from twisted.internet.endpoints import serverFromString
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\twisted\internet\endpoints.py", line 41, in <module>
from twisted.internet.stdio import StandardIO, PipeAddress
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\twisted\internet\stdio.py", line 30, in <module>
from twisted.internet import _win32stdio
File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\twisted\internet\_win32stdio.py", line 9, in <module>
import win32api
ModuleNotFoundError: No module named 'win32api'
Everything before installing channels seems to be working fine.
settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'chat',
'channels',]
CHANNEL_LAYERS = {
'default': {
'BACKEND' : 'asgi_redis.RedisChannelLayer',
'CONFIG':{
'hosts': [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
},
'ROUTING' : 'chat.routing.channel_routing',
},
}
pip freeze:
C:\Users\gdhameeja\Desktop\chatapp\chat>pip freeze
asgi-redis==1.4.3
asgiref==1.1.2
attrs==17.2.0
autobahn==17.9.3
Automat==0.6.0
channels==1.1.8
constantly==15.1.0
daphne==1.3.0
django==1.11.6
hyperlink==17.3.1
incremental==17.5.0
msgpack-python==0.4.8
pytz==2017.2
redis==2.10.6
six==1.11.0
Twisted==17.9.0
txaio==2.8.2
virtualenv==15.1.0
websocket-client==0.44.0
zope.interface==4.4.3
https://github.com/django/channels/issues/498
Refer this post. After you get that error, manually install pypiwin32 package.
pip install pypiwin32
Even though your ide won't recognise channels to import from, ignore it and runserver. It'll work.
I have installed Django(1.8.2) in my Ubuntu 16.04.
When I cloned a working project into it and run the server, I got the following error.
Traceback (most recent call last):
File "manage.py", line 31, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/lib/python2.7/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python2.7/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/lib/python2.7/django/apps/config.py", line 119, in create
import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named django
Observation(s):
I'm able to start a new project and run the server of the same.
The value of INSTALLED_APPS in settings.py is:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Telecommands',
'Telemetry',
'captcha',
'django.contrib.sitemaps',
'djcelery',
'kombu.transport.django',
# 'grappelli',
# 'chronograph',
# 'registration', # Include the registration
)
What have I tried?
Installing django using pip install django==1.8.2.
Since the error was reported with reference to /usr/lib/python2.7/,
I tried:
sudo pip install --install-option="--install-purelib=/usr/lib/python2.7/site-packages/" --ignore-installed django==1.8.2
Further, when I got confused with paths
/usr/local/lib/python2.7/dist-packages,
/usr/lib/python2.7/dist-packages/
and ~/.local/lib/python2.7/dist-packages.
I installed django(1.8.2) to each of these paths one by one,
updating PYTHONPATH in parallel.
I did not get any errors while installing.
Can somebody help me out. Kindly explain the reason for the error as well.
The traceback shows you the error occurs in /usr/lib/python2.7/django/__init__.py, so manage.py has clearly found your Django installation. As an aside, it would be much better to use a virtual env instead of installing in /usr/lib/python2.7/site-packages/.
The problem appears to be that you have kombu.transport.django in your INSTALLED_APPS. The Django transport was removed from kombu in 4.0.
I am trying to install and run Django-registration-redux and whenever I try to include 'registration' in installed apps I am getting an error:
Traceback (most recent call last):
File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\apps\registry.py", line 115, in populate
app_config.ready()
File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\contrib\admin\apps.py", line 22, in ready
self.module.autodiscover()
File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\utils\module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\registration\admin.py", line 2, in <module>
from django.contrib.sites.models import RequestSite
ImportError: cannot import name RequestSite
I have freshly installed Django in myenv virtualenv. manage.py runserver is working fine and loading admin page perfectly without 'registration' app included. FYR: I am using python27 and here is my pip freeze for myenv:
> pip freeze
Django==1.9
django-registration-redux==1.2
wheel==0.24.0
and settings.py inludes the following apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'registration',
]
Do you have any idea on what is the problem here?
I ran into the same error (take a look at the docs, Site is under django.contrib.sites.models and RequestSite under django.contrib.sites.requests). Replace :
from django.contrib.sites.models import RequestSite
by
from django.contrib.sites.requests import RequestSite
in [YourPath]/admin.py, (it's C:\Users\AdamSmith\projects\myvenv\lib\site-packages\registration\admin.py in your case).
This issue is fixed in django-registration-redux 1.3. See https://github.com/macropin/django-registration/issues/132.