Django: Collect Static WinError 3 - python

ive got a problem here. When i try to "collectstatic" from manage.py it just kicks me off with following error:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 3.1.3\helpers\pycharm\django_manage.py", line 23, in <module>
run_module(manage_file, None, '__main__', True)
File "C:\Python34\lib\runpy.py", line 182, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Python34\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Python34\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:/Users/mszalewski/PycharmProjects/OwnPixel_com\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 285, in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 415, in handle
return self.handle_noargs(**options)
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 173, in handle_noargs
collected = self.collect()
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 103, in collect
for path, storage in finder.list(self.ignore_patterns):
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\finders.py", line 106, in list
for path in utils.get_files(storage, ignore_patterns):
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\utils.py", line 25, in get_files
directories, files = storage.listdir(location)
File "C:\Python34\lib\site-packages\django\core\files\storage.py", line 250, in listdir
for entry in os.listdir(path):
FileNotFoundError: [WinError 3] Das System kann den angegebenen Pfad nicht finden: 'C:\\Users\\mszalewski\\PycharmProjects\\static\\static'
Process finished with exit code 1
The following is my settings.py:
import os
import os.path
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'OwnPixel_com.urls'
WSGI_APPLICATION = 'OwnPixel_com.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(BASE_DIR), "static", "templates").replace('\\','/')
)
if DEBUG:
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "static-only").replace('\\', '/')
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "media").replace('\\', '/')
STATICFILES_DIRS = (
os.path.join(os.path.dirname(BASE_DIR), "static", "static").replace('\\', '/'),
)
At least my extendes urls.py
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
Iam very sure that its the double backslash in the path (at the end of the error code).
I hope you can help me to fix my problem.
THANKS!!!
Regards, Marvyn

What does your Directory structure actually look like?
I doubt that 'C:\Users\mszalewski\PycharmProjects\static\static' is the folder you're intending to use for the Project specific static files.
My guess is that you want to change
os.path.join(os.path.dirname(BASE_DIR), "static", "static").replace('\\', '/')
to
os.path.join(BASE_DIR, "static", "static")
Or something very similar. And don't worry about the '\\' and '/'. Python will actually get along just fine with some very odd combinations of them in the same path.

Because you are in a virtual directory (assuming you've already activated the virtual env like so : source <*Scripts* or *bin*>/activate), the path that STATIC_ROOT and STATICFILES_DIRS expect are different.
1) STATIC_ROOT is expecting the location of the static files on your local machine (whether that be the cloud server you are serving these files on the computer that you are developing on) --> i.e. something like STATIC_ROOT = 'C:/Users/<user>/Desktop/django_env_folder/mysite/static/mysite'
2) STATICFILES_DIRS on the other hand is expecting the virtual_env path (remember, when you activate your virtual env using the command above, the paths that os.<method>() requires are different (do some debugging to see, try running os.listdir('C:/....') and you will notice different results than expected. SO try something like this for STATICFILES_DIRS --> STATICFILES_DIRS = [
'mysite/static/mysite',
]
** This solution definitely works when serving on localhost, make sure Debug = True in your settings.py.

Related

Django Whitenoise causes error collecting static

When I run collectstatic on my Django site, I always get an error.
This is my settings.py:
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 3.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATES_DIRS = os.path.join(BASE_DIR, 'templates')
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), )
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'not showing it here'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'news',
'writers',
]
INSTALLED_APPS += ('django_summernote', )
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'news.middleware.TimezoneMiddleware',
]
ROOT_URLCONF = 'mysite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATES_DIRS],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'news.context_processors.common_variables'
],
},
},
]
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'
X_FRAME_OPTIONS = 'SAMEORIGIN'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
When I run collectstatic I get:
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 "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\core\management\base.py", line 371, in execute
output = self.handle(*args, **options)
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\contrib\staticfiles\management\commands\collectstatic.py", line 194, in han
dle
collected = self.collect()
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\contrib\staticfiles\management\commands\collectstatic.py", line 132, in col
lect
for original_path, processed_path, processed in processor:
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\wh
itenoise\storage.py", line 148, in post_process_with_compression
for name, hashed_name, processed in files:
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\wh
itenoise\storage.py", line 88, in post_process
for name, hashed_name, processed in files:
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\contrib\staticfiles\storage.py", line 399, in post_process
yield from super().post_process(*args, **kwargs)
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\contrib\staticfiles\storage.py", line 231, in post_process
for name, hashed_name, processed, _ in self._post_process(paths, adjustable_
paths, hashed_files):
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\contrib\staticfiles\storage.py", line 288, in _post_process
content = pattern.sub(converter, content)
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\contrib\staticfiles\storage.py", line 187, in converter
hashed_url = self._url(
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\contrib\staticfiles\storage.py", line 126, in _url
hashed_name = hashed_name_func(*args)
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\contrib\staticfiles\storage.py", line 338, in _stored_name
cache_name = self.clean_name(self.hashed_name(name))
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\wh
itenoise\storage.py", line 166, in hashed_name
name = super(CompressedManifestStaticFilesStorage, self).hashed_name(
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\contrib\staticfiles\storage.py", line 87, in hashed_name
if not self.exists(filename):
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\core\files\storage.py", line 311, in exists
return os.path.exists(self.path(name))
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\contrib\staticfiles\storage.py", line 41, in path
return super().path(name)
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\core\files\storage.py", line 324, in path
return safe_join(self.location, name)
File "C:\Users\Me\AppData\Local\Programs\Python\Python38\lib\site-packages\dj
ango\utils\_os.py", line 29, in safe_join
raise SuspiciousFileOperation(
django.core.exceptions.SuspiciousFileOperation: The joined path (E:\Folder\WebProjects\website\mysite\img\arrow-left.png) is l
ocated outside of the base path component (E:\Folder\WebProjects\website\mysite\staticfiles)
I've searched but I can't find E:\Folder\WebProjects\website\mysite\img\arrow-left.png
This only happens when I use Whitenoise. If I use the normal Django static service, It works but the CSS doesn't show. I'm using Heroku
EDIT: Here's my wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
application = get_wsgi_application()
Comment whitenoise part in wsgi.py then run collectstatic and uncomment whitenoise part while deployment.
Also no need of STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage
sample for wsgi.py
import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
application = get_wsgi_application()
application = DjangoWhiteNoise(application)

Heroku django "OSError: [Errno 2] No such file or directory: '/static/static'"

I am new to django and heroku. This is the error I'm getting when I deployed my git repository to heroku. Please suggest the changes that I need to change. Thank you in advance
(website) C:\Users\website\src>heroku run python manage.py collectstatic
--noinput
Running python manage.py collectstatic --noinput attached to terminal... up, run.1690
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__
.py", line 385, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__
.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py"
, line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py"
, line 338, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py"
, line 533, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle_noargs
collected = self.collect()
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 111, in list
for path in utils.get_files(storage, ignore_patterns):
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/utils.py", line 27, in get_files
directories, files = storage.listdir(location)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/files/storage.py",
line 270, in listdir
for entry in os.listdir(path):
OSError: [Errno 2] No such file or directory: '/static/static'
settings.py
STATIC_URL = '/static/'
# Template location
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(BASE_DIR), "static", "templates" ),
)
if DEBUG:
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "static-only" )
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "media" )
STATICFILES_DIRS = (
os.path.join(os.path.dirname(BASE_DIR), "static", "static" ),
)
If you have declared your 'STATICFILES_DIRS' variable as below,
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
ensure:
a static folder (the folder must be named as you specified in the 'STATICFILES_DIRS' variable) exists.
it contains a file. You can name a dummy file as '.any' if you've got no file yet.
Currently, it seems that the error comes from the STATICFILES_DIRS var points to a directory that does not exist:
STATICFILES_DIRS = (os.path.join(os.path.dirname(BASE_DIR), "static", "static" )
Go to your Django project directory, find the static repository, and note the absolute location.
Then, edit the STATICFILES_DIRS variable in settings.py sothat it points to this location.
For me (that does not imply it should be the same for you), it looks like this:
STATICFILES_DIRS = (os.path.join(BASE_DIR, '../myapp/static'),)

Django not able to render context when in shell

This is what I am trying to run. When I run the server and run these lines within a view and then return an HttpResponse, then everything goes fine. However when I run python manage.py shell and then try to run through these lines then I get an error:
product = Product.objects.get(pk=4)
template = loader.get_template('weekly-email.html')
user = User.objects.get(pk=1)
body = template.render(Context({
'user': user,
'product': product,
}))
Output:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/template/backends/django.py", line 74, in render
return self.template.render(context)
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/template/base.py", line 209, in render
return self._render(context)
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/template/base.py", line 201, in _render
return self.nodelist.render(context)
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/template/base.py", line 903, in render
bit = self.render_node(node, context)
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/template/base.py", line 917, in render_node
return node.render(context)
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/template/base.py", line 963, in render
return render_value_in_context(output, context)
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/template/base.py", line 939, in render_value_in_context
value = localize(value, use_l10n=context.use_l10n)
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/utils/formats.py", line 181, in localize
return number_format(value, use_l10n=use_l10n)
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/utils/formats.py", line 162, in number_format
get_format('DECIMAL_SEPARATOR', lang, use_l10n=use_l10n),
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/utils/formats.py", line 110, in get_format
for module in get_format_modules(lang):
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/utils/formats.py", line 82, in get_format_modules
modules = _format_modules_cache.setdefault(lang, list(iter_format_modules(lang, settings.FORMAT_MODULE_PATH)))
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/utils/formats.py", line 51, in iter_format_modules
if not check_for_language(lang):
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 181, in check_for_language
return _trans.check_for_language(lang_code)
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/functools.py", line 472, in wrapper
result = user_function(*args, **kwds)
File "/Users/croberts/.virtualenvs/testproj/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 409, in check_for_language
if not language_code_re.search(lang_code):
TypeError: expected string or buffer
edit: and here is my settings.py:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
DEBUG = True
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'SECRET'
ALLOWED_HOSTS = []
AUTH_USER_MODEL = 'crunch.User'
STATICFILES_DIRS = (
'/Users/croberts/testproj/static/',
)
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crunch',
'emailmanager',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'testproj.urls'
WSGI_APPLICATION = 'testproj.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'database'),
}
}
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'MST'
USE_I18N = True
USE_L10N = True
USE_TZ = False
STATIC_URL = '/static/'
MEDIA_ROOT = BASE_DIR+'/media/'
MEDIA_URL = '/media/'
Also, I am using django 1.8.
This is a known issue and will be fixed in 1.8.1.
Meanwhile, you can manually activate a language in your shell to fix it:
from django.utils.translation import activate
activate('en') # or any language code
UPDATE: 1.8.1 has been released, so the best solution is to upgrade to the latest 1.8.x version.

Django Tincymce, AttributeError: 'NoneType' object has no attribute 'endswith'

I added Tinymce to my django project. But now i cant start django test server. I'm getting following error.
(postjust)erkans-MacBook-Air:postjust erkan$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/erkan/Dev/Python/virtualenvs/postjust/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/erkan/Dev/Python/virtualenvs/postjust/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/Users/erkan/Dev/Python/virtualenvs/postjust/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/erkan/Dev/Python/virtualenvs/postjust/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/erkan/Dev/Python/virtualenvs/postjust/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/erkan/Dev/Python/virtualenvs/postjust/lib/python2.7/site-packages/tinymce/models.py", line 6, in <module>
from tinymce import widgets as tinymce_widgets
File "/Users/erkan/Dev/Python/virtualenvs/postjust/lib/python2.7/site-packages/tinymce/widgets.py", line 10, in <module>
import tinymce.settings
File "/Users/erkan/Dev/Python/virtualenvs/postjust/lib/python2.7/site-packages/tinymce/settings.py", line 16, in <module>
JS_ROOT = getattr(settings, 'TINYMCE_JS_ROOT',os.path.join(settings.STATIC_ROOT, 'tiny_mce'))
File "/Users/erkan/Dev/Python/virtualenvs/postjust/bin/../lib/python2.7/posixpath.py", line 77, in join
elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
I have Static_Url in my settings.
my settings.py :
"""
Django settings for postjust project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'jb-#(98(ew4kkociwv+2y(3799r*vug7-$g)e=6wsxigrk30=!'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = ['localhost','127.0.0.1']
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'blog',
'pages',
'tinymce'
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'pages.context_processors.pages'
)
ROOT_URLCONF = 'postjust.urls'
WSGI_APPLICATION = 'postjust.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
i try yo set static_url to '' and '/'. What is the solution ?
You need to have a STATIC_ROOT in your settings, not only STATIC_URL. Docs can be found here

TypeError: unhashable type: 'bytearray'

I'm new to django and trying to create a Homepage. But I've already problems with the database setup. When I run
python manage.py migrate
I get this error
(env) paul#Kreker-Server:~/public_html/p_kreker$ python manage.py migrate
Operations to perform:
Apply all migrations: auth, sessions, contenttypes, admin
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying sessions.0001_initial... OK
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 165, in handle
emit_post_migrate_signal(created_models, self.verbosity, self.interactive, connection.alias)
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/sql.py", line 268, in emit_post_migrate_signal
using=db)
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/dispatch/dispatcher.py", line 198, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/contrib/auth/management/__init__.py", line 64, in create_permissions
if not is_latest_migration_applied('auth'):
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/db/migrations/loader.py", line 292, in is_latest_migration_applied
loader = MigrationLoader(connection)
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/db/migrations/loader.py", line 184, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 60, in applied_migrations
return set(tuple(x) for x in self.migration_qs.values_list("app", "name"))
TypeError: unhashable type: 'bytearray'
I'm using python-3.4, django-1.7.4 and for the SQL connection mysql-connector-python-2.0.2. For this project I've created a virtual environment with the python 3 venv. I host this project on github: https://github.com/pkreker/p_kreker
Thank you in advance!
edit settings.py:
"""
Django settings for p_kreker project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#l)bvja#q45ud2d813g*i+n2=1#kbf#nzqm6()c)dv116pqq^p'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'p_kreker.urls'
WSGI_APPLICATION = 'p_kreker.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'NAME': 'p_kreker',
'ENGINE': 'mysql.connector.django',
'USER': 'paul',
'PASSWORD': 'm2aJup2fHYDdArGT',
'OPTIONS': {
'autocommit': True,
},
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'de-de'
TIME_ZONE = 'Europe/Berlin'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
Since the bug headline does not specify "Django", I expect a number of Python 3 newbies will end up here. Note that the hashable/immutable counterpart to "bytearray" is the type "bytes".
>>> b1 = bytearray([1, 2, 3])
>>> s = set()
>>> s.add(b1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'bytearray'
>>> b2 = bytes(b1)
>>> b2
b'\x01\x02\x03'
>>> s.add(b2)
>>>
I think this is likely to be a bug in mysql-connector-python - does it support Django 1.7.4? Your code works fine if you run it with sqlite.
If the project is on an older version of Django for example 1.11.16, try explicit decoding by calling the method .decode("utf-8") in introspection.py file.
if django.VERSION >= (1, 8):
return [
TableInfo(row[0].decode("utf-8"), {'BASE TABLE': 't', 'VIEW': 'v'}.get(row[1].decode("utf-8")))
for row in cursor.fetchall()
]
else:
return [row[0] for row in cursor.fetchall()]
introspection.py file path:
C:\Python27\Lib\site-packages\mysql\connector\django\introspection.py
method prototype:
def get_table_list(self, cursor):
I had this error today. I had created my db as utf8_bin collation, which I assume was the reason for it. Dropped the DB, re-created with utf8_general_ci, ran migrations, and it worked fine.

Categories