Unable to connect to Django with oracle ebs database - django

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'
]

Related

Application labels aren't unique, duplicates: account. Django

I know there are Duplicates of this question, but they didn't solve the issue.
my django app is conflicting between django-user-acccounts; account and allauth.account
M Installed App
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts.apps.AccountsConfig',
'django.contrib.sites',
# 'allauth',
'allauth.account', # django-allauth # conflict
'allauth.socialaccount',
'crispy_forms',
'account', # django-user-accounts #conflict
'pinax.referrals',
'kingEstateCore',
'widget_tweaks',
]
I've tried renaming the account package inside my site_packages but no success.
I've also tried adding AppConfig but there was no apps.py module insite my site_packages/account.
Any Ideas pls
Error TraceBack
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "c:\users\user\appdata\local\programs\python\python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\apps\registry.py", line 95, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: account

Issue with importing rest_framework inside django app

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

Import Error: No module named django - for specific project

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.

ImportError: cannot import name RequestSite when inlude 'registration' in installed apps

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.

Django: Error when trying to add a new app

I am trying to follow the steps here:
http://dev.svetlyak.ru/optional-email-in-django-comments-en/
to make the "Email Address" field in the Django comments app optional. Specifically, I created a file called 'mycomments.py' with the following contents:
from django import forms
from django.contrib.comments.forms import CommentDetailsForm
from django.utils.translation import ungettext, ugettext_lazy as _
class CommentForm(CommentDetailsForm):
email = forms.EmailField(label=_("Email address"), required=False)
def get_form():
return CommentForm
And placed it in the root folder for my Django project (the same folder that contains manage.py and settings.py). Then, I added 'mycomments' to the settings.py file as follows:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.comments',
'blogs',
'mycomments',
)
COMMENTS_APP = 'mycomments'
But then when I do 'python manage.py runserver', I get the following error:
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x8bb208c>>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 83, in load_app
if not module_has_submodule(app_module, 'models'):
File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 17, in module_has_submodule
for entry in package.__path__: # No __path__, then not a package.
AttributeError: 'module' object has no attribute '__path__'
And the dev server doesn't start up. Did I do something wrong?
Django app should be (at minimum) a directory with __init__.py and models.py files. So create mycomments dir, put your code in __init__.py and add empty models.py there.