I have the following structure in a django project.
I have a providers.py file in which:
from django.conf import settings
from project.utils.firewalls import fw
In providers I need to get some vars defined in settings.
Then in firewalls.py, I have:
from django.conf import settings
Also in firewalls.py, I do have some code which needs to get a variable that is defined in settings.
When I try to do:
python manage.py --settings=project.settings.local it will complain about not defining SECRET_KEY, although it is defined.
It has to do with the fact that I am importing django.conf.settings in both files.
How can I avoid that ?
For the moment I've hardcoded the value of the var in the firewalls.py, but I would like to avoid that.
Edit:
Add Stacktrack:
➤ python project/manage.py runserver --settings=project.settings.local
Traceback (most recent call last):
File "project/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 60, in execute
super().execute(*args, **options)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 67, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 107, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/bsabin/Projects/repo/venv/lib64/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/bsabin/Projects/repo/project/project/settings/local.py", line 1, in <module>
from .base import *
File "/home/bsabin/Projects/repo/project/project/settings/base.py", line 21, in <module>
from project.utils.providers import AProvider, BProvider, CProvider
File "/home/bsabin/Projects/repo/project/project/utils/providers.py", line 6, in <module>
from project.utils.firewalls import fw
File "/home/bsabin/Projects/repo/project/project/utils/firewalls.py", line 29, in <module>
fw = get_firewall_instance()
File "/home/bsabin/Projects/repo/project/project/utils/firewalls.py", line 11, in get_firewall_instance
token = settings.DO_TOKEN.get('token')
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 126, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
I am assuming the problem you are facing is that you are using a function in a different file to pull some configuration data in settings, and inside that file you are importing the settings as well. In ideal case, it should trigger circular dependency error. But as django.conf.settings is lazy, it will raise Improper Configuration Error.
If you need some variables for configuration, why don't you pass the variable to the function directly. For example:
# in settings:
from project.utils.providers import AProvider, BProvider, CProvider
SOME_VARIABLE = AProvider(token="Your Token")
Then inside providers
class AProvider(...):
def __init__(self, *args, **kwargs):
token = kwargs.get('token')
# rest of the code
# somewhere in the code
fw = get_firewall_instance(self.token)
In firewall.py:
def get_firewall_instance(token_from_settings):
token = token_from_settings
Related
I am having this issue when I try to run the server in Pycharm. I am new to Django and downloaded this project as a backend for my react application. I have generated a Secret Key using:
from django.core.management.utils import get_random_secret_key
print(get_random_secret_key())
exit()
I added this Secret key to settings.py file as well.
Error Log which I get:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\zabim\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "C:\Users\zabim\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\apps\registry.py", line 122, in populate
app_config.ready()
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\admin\apps.py", line 27, in ready
self.module.autodiscover()
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\admin\__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\utils\module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Users\zabim\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\auth\admin.py", line 6, in <module>
from django.contrib.auth.forms import (
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\auth\forms.py", line 11, in <module>
from django.contrib.auth.tokens import default_token_generator
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\auth\tokens.py", line 117, in <module>
default_token_generator = PasswordResetTokenGenerator()
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\auth\tokens.py", line 18, in __init__
self.secret = self.secret or settings.SECRET_KEY
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\conf\__init__.py", line 90, in __getattr__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
Go to your settings.py
SECRET_KEY = ""
There should already be a value, if not, copy paste the one from the print statement.
Have a look at the different module for the settings, you could have one for local, production and base for example, make sure all of them have a secret key.
Learn about secret key
This is very important to understand, I strongly advise to have a look at the Django Tutorial as this error should be obvious to most beginners in Django
I am trying to push my code on Heroku, I have hidden my secret key using environ package but now Heroku is not able to access it since I have ignored my .env file using gitignore, I have read about config vars in Heroku but I am having trouble understanding how do I make Django access those values
import os
import environ
# from .secret import key
env = environ.Env()
environ.Env.read_env()
SECRET_KEY = env('KEY',default=env('SECRET_KEY'))
updated code
In the log, it is giving me error like this
warnings.warn(
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.8/site-packages/environ/environ.py", line 277, in get_value
value = self.ENVIRON[var]
File "/app/.heroku/python/lib/python3.8/os.py", line 675, in __getitem__
raise KeyError(key) from None
KeyError: 'SECRET_KEY'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/__init__.py", line 244, in fetch_command
settings.INSTALLED_APPS
File "/app/.heroku/python/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/app/.heroku/python/lib/python3.8/site-packages/django/conf/__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "/app/.heroku/python/lib/python3.8/site-packages/django/conf/__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/tmp/build_067d1d45/food_deliveryapp/settings.py", line 22, in <module>
SECRET_KEY = os.environ.get('KEY',env('SECRET_KEY'))
File "/app/.heroku/python/lib/python3.8/site-packages/environ/environ.py", line 127, in __call__
return self.get_value(var, cast=cast, default=default, parse_default=parse_default)
File "/app/.heroku/python/lib/python3.8/site-packages/environ/environ.py", line 281, in get_value
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
! Push rejected, failed to compile Python app.
! Push failed
For every variable in .env create a Config Var, make sure names are UPPERCASE.
In your code you can access them via environ (map with all env variables):
my_secret = (os.environ.get("MY_SECRET", 'dev default value')
I am using Django and Wagtail to create a site, which had been working well for some time. However, after some problems with anaconda, reinstalling etc, I now get this problem when I run python manage.py runserver:
ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models.fields' (C:\Users\Tomo_\AppData\Roaming\Python\Python38\site-packages\django\db\models\fields\__init__.py)
I am not entirely sure what to do, as nothing has changed in my settings, and there isn't even a fields file, but rather a fields folder. It's like it's looking for an object in a folder.
Entire trace:
(base)>python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\base.py", line 368, in execute
self.check()
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\ProgramData\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\ProgramData\Anaconda3\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "G:\OneDrive\Academia\Computer-Science\Portfolio\Wagtail\portfolio\portfolio\urls.py", line 6, in <module>
from wagtail.admin import urls as wagtailadmin_urls
File "C:\ProgramData\Anaconda3\lib\site-packages\wagtail\admin\urls\__init__.py", line 14, in <module>
from wagtail.admin.urls import pages as wagtailadmin_pages_urls
File "C:\ProgramData\Anaconda3\lib\site-packages\wagtail\admin\urls\pages.py", line 4, in <module>
from wagtail.admin.views.pages import (
File "C:\ProgramData\Anaconda3\lib\site-packages\wagtail\admin\views\pages\history.py", line 11, in <module>
from wagtail.admin.filters import PageHistoryReportFilterSet
File "C:\ProgramData\Anaconda3\lib\site-packages\wagtail\admin\filters.py", line 1, in <module>
import django_filters
File "C:\Users\Tomo_\AppData\Roaming\Python\Python38\site-packages\django_filters\__init__.py", line 4, in <module>
from .filters import *
File "C:\Users\Tomo_\AppData\Roaming\Python\Python38\site-packages\django_filters\filters.py", line 12, in <module>
from .conf import settings
File "C:\Users\Tomo_\AppData\Roaming\Python\Python38\site-packages\django_filters\conf.py", line 5, in <module>
from .utils import deprecate
File "C:\Users\Tomo_\AppData\Roaming\Python\Python38\site-packages\django_filters\utils.py", line 10, in <module>
from django.db.models.fields import FieldDoesNotExist
ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models.fields' (C:\ProgramData\Anaconda3\lib\site-packages\django\db\models\fields\__init__.py)
Not much info has come from googling, so any help would be much appreciated.
Wagtail version = 2.11.3
Django version = 3.1.4
Thanks.
For those who come here in future and needs a more precise solution than just --upgrade, exactly django-filters 2.3 fixes that bug.
https://github.com/carltongibson/django-filter/issues/1261#issuecomment-680289892
I solved this by deleting all django and wagtail modules in my python38/site-packages folders and reinstalling them with pip install [packagenames] --upgrade command.
I would like to enable my django-cms instance to host multiple sites.
For that I created two different sites in the admin panel.
Unfortunately only one site is shown because I needed to hardcode the SITE_ID in the project settings.
According to https://github.com/django/django/pull/2460 this is not a mandatory setting anymore. But my Django 1.10.7 instance shows the following traceback if I delete it:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/var/www/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/var/www/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/var/www/venv/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/var/www/venv/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/var/www/venv/lib/python3.5/site-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/var/www/venv/lib/python3.5/site-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/var/www/venv/lib/python3.5/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/__init__.py", line 2, in <module>
import cms.admin.pageadmin
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/pageadmin.py", line 39, in <module>
from cms.admin.forms import (
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/forms.py", line 85, in <module>
class PageForm(forms.ModelForm):
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/forms.py", line 86, in PageForm
language = forms.ChoiceField(label=_("Language"), choices=get_language_tuple(),
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/i18n.py", line 76, in get_language_tuple
return [(lang['code'], lang['name']) for lang in get_languages(site_id)]
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/i18n.py", line 23, in get_languages
site_id = get_site_id(site_id)
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/conf.py", line 294, in get_site_id
return settings.SITE_ID
File "/var/www/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 49, in __getattr__
return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'SITE_ID'
Looks like SITE_ID is required by Django CMS, it's in the traceback
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/conf.py", line 294, in get_site_id
return settings.SITE_ID
I solved to problem differently.
I used the plugin djangocms-multisite.
I don't know if it is the best solution but it works.
I'm trying to get Django development started on my Windows 7 partition and I'm finding that whenever I run a Django command I get:
'git' is not recognized as an internal or external command,
operable program or batch file.
Often 3-4 times in a row but then the command seems to execute fine. While it doesn't seem to be affecting the execution of the commands, I don't like having errors thrown every time I do something, makes me nervous (and there's very possibly something I'm missing that's going wrong). I tried adding git to my environment variables but it didn't seem to work, here is the current PATH value.
;C:\Chocolatey\bin;C:\tools\mysql\current\bin;C:\Program Files (x86)\Git\bin
Any additional suggestions to try are welcome. I'm using Windows 7 and the most recent version of Python, Django, and Git (just downloaded them today).
EDIT: I ran the commands again in response to some of your comments (thanks for those btw). Here's the output to python manage.py runserver
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\django\db\backends\mysql\base.py", line 14, in
import MySQLdb as Database
ImportError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 416, in execute_from_command_line
utility.execute()
File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 408, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python33\lib\site-packages\django\core\management\base.py", line 244, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python33\lib\site-packages\django\core\management\base.py", line 286, in execute
translation.activate('en-us')
File "C:\Python33\lib\site-packages\django\utils\translation\__init__.py", line 142, in activate
return _trans.activate(language)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 218, in activate
_active.value = translation(language)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 201, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 183, in _fetch
app = import_module(appname)
File "C:\Python33\lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1586, in _gcd_import
File "<frozen importlib._bootstrap>", line 1567, in _find_and_load
File "<frozen importlib._bootstrap>", line 1534, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1024, in load_module
File "<frozen importlib._bootstrap>", line 1005, in load_module
File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 870, in _load_module
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "C:\Python33\lib\site-packages\django\contrib\admin\__init__.py", line 7, in <module>
from django.contrib.admin.sites import AdminSite, site
File "C:\Python33\lib\site-packages\django\contrib\admin\sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "C:\Python33\lib\site-packages\django\contrib\admin\forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "C:\Python33\lib\site-packages\django\contrib\auth\forms.py", line 16, in <module>
from django.contrib.auth.models import User
File "C:\Python33\lib\site-packages\django\contrib\auth\models.py", line 40, in <module>
class Permission(models.Model):
File "C:\Python33\lib\site-packages\django\db\models\base.py", line 108, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Python33\lib\site-packages\django\db\models\base.py", line 291, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Python33\lib\site-packages\django\db\models\options.py", line 141, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Python33\lib\site-packages\django\db\__init__.py", line 39, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python33\lib\site-packages\django\db\utils.py", line 192, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python33\lib\site-packages\django\db\utils.py", line 107, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python33\lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Python33\lib\site-packages\django\db\backends\mysql\base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
And here's the output to python manage.py syncdb
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\django\db\backends\mysql\base.py", line 14, in <module>
import MySQLdb as Database
ImportError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 416, in execute_from_command_line
utility.execute()
File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 408, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python33\lib\site-packages\django\core\management\base.py", line 244, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python33\lib\site-packages\django\core\management\base.py", line 286, in execute
translation.activate('en-us')
File "C:\Python33\lib\site-packages\django\utils\translation\__init__.py", line 142, in activate
return _trans.activate(language)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 218, in activate
_active.value = translation(language)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 201, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 183, in _fetch
app = import_module(appname)
File "C:\Python33\lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1586, in _gcd_import
File "<frozen importlib._bootstrap>", line 1567, in _find_and_load
File "<frozen importlib._bootstrap>", line 1534, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1024, in load_module
File "<frozen importlib._bootstrap>", line 1005, in load_module
File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 870, in _load_module
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "C:\Python33\lib\site-packages\django\contrib\admin\__init__.py", line 7, in <module>
from django.contrib.admin.sites import AdminSite, site
File "C:\Python33\lib\site-packages\django\contrib\admin\sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "C:\Python33\lib\site-packages\django\contrib\admin\forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "C:\Python33\lib\site-packages\django\contrib\auth\forms.py", line 16, in <module>
from django.contrib.auth.models import User
File "C:\Python33\lib\site-packages\django\contrib\auth\models.py", line 40, in <module>
class Permission(models.Model):
File "C:\Python33\lib\site-packages\django\db\models\base.py", line 108, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Python33\lib\site-packages\django\db\models\base.py", line 291, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Python33\lib\site-packages\django\db\models\options.py", line 141, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Python33\lib\site-packages\django\db\__init__.py", line 39, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python33\lib\site-packages\django\db\utils.py", line 192, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python33\lib\site-packages\django\db\utils.py", line 107, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python33\lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Python33\lib\site-packages\django\db\backends\mysql\base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
Seems to be a result of missing MySQLdb. Does anyone have a link to this module? I can't find anything on Pypi called this exactly, I'm not sure which one it's looking for.
is it possible that you overwrote your "manage.py" with something which tries to start git? Your manage.py should look like this:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourapp.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
Or do you have a "git" commant in your settings.py?
EDIT after your error logs:
Did you install the MySQL-python package (see docs at https://docs.djangoproject.com/en/dev/topics/install/#get-your-database-running) AND MySQLdb (see https://docs.djangoproject.com/en/dev/ref/databases/#mysqldb)? Both are required when using MySQL.
If yes, do you get the same results when switching to a sqlite database?