Directory 'uploads/' for the site filebrowser.filebrowser does not exist - django

I've managed to use django-filebrowser to upload file via TinyMCE based on this documentation:
http://django-filebrowser.readthedocs.org/en/latest/quickstart.html
I've put reference to tiny_mce.js and tinymce_setup.js from Grappeli folder to my template,now TinyMCE works.
but when testing filebrowser with this command:python manage.py test filebrowser I get this error:Directory 'uploads/' for the site filebrowser.filebrowser does not exist. ,of course all of project throw this error.I searched this error in google but no proper result!
Note:I've gotten Grappeli worked already.
what do U think?

For those having problems with filebrowser setup, here is what is required to set it up after you install it.
Add it to your INSTALLED_APPS as:
'filebrowser',
In your urls.py master file, add the file browser pattern:
from filebrowser.sites import site
urlpatterns = patterns('',
(r'^admin/filebrowser/', include(site.urls)),
....)
Then make sure you have your MEDIA_ROOT set and that by default the uploads/ folder exists in the MEDIA_ROOT. You can change the uploads folder by settting FILEBROWSER_DIRECTORY to something different:
FILEBROWSER_DIRECTORY = 'filebrowser_uploads/'
Then I usually run a test and see if anything is broken and why:
python manage.py test filebrowser
I don't know why the setup doesn't create the default directory for it if MEDIA_ROOT exists. Instead it checks if MEDIA_ROOT + FILEBROWSER_DIRECTORY exist and it fails if it doesn't. More on this in the quick start guide.

Related

django: how to load the static files with hash/md5 appending correctly?

using Django 3
I followed the Django Doc
https://docs.djangoproject.com/en/3.0/ref/contrib/staticfiles/#manifeststaticfilesstorage
to export my static files with a hash appending.
settings.py production
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
static_root folder (output)
static_root/
staticfiles.json
static_root/css/
project_styles.87c2920e7bc3.css
project_styles.css
everything is collected correctly.
Afterwards i uploaded everything to my apache static server.
And i set off / comment the STATICFILES_STORAGE . That is how i understand the Doc´s? If i leave this setting on in production i get an 500 Error.
settings.py production
# STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
After restarting my Django app in production, my site is still loading project_styles.css but not the hash Version project_styles.87c2920e7bc3.css in my browser. Even if i delete project_styles.css Django will not serve the hash version.
Question
Did i miss some settings in the settings.py in production mode?
In the Doc´s they mention to set STATICFILES_STORAGE = django.contrib.staticfiles.storage.StaticFilesStorage but it shows no difference. And as it is mentioned it´s only for testing.
What i have to do to load the correct static hash version in production? do i have to set something in my templates, so that django will look into the json file for the correct hash version? Or do i have to name the hash file?
Alright, the Problem was that i wanted two different STATIC_ROOT Paths. One for Development and one for Production, because i want all my Development stuff in one Project folder. Because if you collectstatic with the STATIC_ROOT of your apache server, django will export it for instance into c:/var/www/your/server/static while i wanted it to c:/webprojects/myproject_1/static_root_exports and later upload these files on my server separately.
So i set two different Path depending on DEV_STATIC off / on in my django-environ file. Django will set the correct Path.
.env
DEBUG=off
# --- applies media server & sets MEDIA_ROOT & STATIC_ROOT
DEV_STATIC=on
<...>
STATIC_ROOT_DEV=static_root_exports
STATIC_ROOT_PROD=/var/www/myUserName/html/myproject_assets/static
<...>
setting.py
# -- Set for Hash
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
# --- STATIC_ROOT
if DEV_STATIC == True:
STATIC_ROOT = SERVER_DIR.joinpath(env('STATIC_ROOT_DEV'))
else:
STATIC_ROOT = env('STATIC_ROOT_PROD')

Static method returning empty list in Django

I am trying to run a Django app on local server. It works fine on mu Ubuntu machine but in mac, I can't get the CSS for
localhost:8000/admin
and
localhost:8000/docs to load.
On digging further, I found out that the static URL in main "urls.py" file
return an empty list instead of a URL pattern.
Does anyone have an idea why it is like that on the new mac system?
I have had the same issue. I was able to fix it manually by adding the following snippet to my urls.py file in the project (the urls.py file next to settings.py)...
from django.conf import settings
from django.conf.urls.static import static
from django.views.static import serve
. . .
if settings.TESTING_PRODUCTION:
urlpatterns += [
re_path(r'^static/(?P<path>.*)$', serve, {
'document_root': settings.STATIC_ROOT,
}),
]
I pulled this together from the Django Docs here.
I needed to do this so that I could test the "production" environment with manage.py runserver by manually setting DEBUG = False in settings.py which changes a few other URLs and also turns off trace printing in my code.
In my settings.py file, I have some code to set TESTING_PRODUCTION to True as well. But in actual production with a real web server, the code should set TESTING_PRODUCTION to False so that the static files can be served by the webserver directly and not through Django.

django-ckeditor: ckeditor js file not included

I'm trying to use the ckeditor package from here: https://github.com/shaunsephton/django-ckeditor . I have followed the directions, but I can't seem to figure out what the path is to include the ckeditor.js file.
Every time I go to a page with the ckeditor widget/field I get a javascript error because of this:
Uncaught ReferenceError: CKEDITOR is not defined
I did run collectstatic etc..
Have another look at the docs for serving static files.
If you're in development and using runserver you'll want to add the following to your url conf -
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# ... the rest of your URLconf goes here ...
urlpatterns += staticfiles_urlpatterns()
See this section of the docs specifically.

Django Admin has broken CSS link through apache, but works in runserver mode

For some reason, at some point the django administration got broken. The css is missing.
Here are my settings:
MEDIA_ROOT = os.path.normpath(os.path.join(SITE_ROOT, 'media/'))
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/admin_media/'
However, the generated line on the admin page is still:
<link rel="stylesheet" type="text/css" href="/admin_media/css/base.css" />
but the site gives me 404 on this file.
And it gets better - if I use apache to view the project, that problem occurs. If I use python manage.py runserver the admin works well.
Any clues to why that might be happening?
- restarted apache, that didn't help.
here is what i have in the urls file:
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
Ok, I figured it out.
For production server, you have to setup a link to the setting you provided. For me, i chose admin_media folder, in the settings.py file:
ADMIN_MEDIA_PREFIX = '/admin_media/'
And in order to tell apache to look for files, you have to edit your sites-enabled file by adding the line:
Alias /admin_media/ /usr/lib/python2.6/dist-packages/django/contrib/admin/media/
Note though, that this is the path to the django contrib admin as installed on my server. Your server might have a different installation, so look up your settings. find out where your python is installed by copy pasting this in terminal:
python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
Good luck to everybody!

Why am I getting absolute urls in Satchmo when I upload product images locally?

I'm doing some local development using Django and Satchmo. When I upload product images locally via the admin, the path to the image shows up as an absolute path, complete with drive letter, rather than the proper relative path.
Stranger still, Satchmo saves both the original image and the thumbnails it generates in both me /media/ directory and /media/images/ directory, the latter being where I want them to go.
The relavent settings are as follows:
# path relative to the settings.py file
DIRNAME = os.path.abspath(os.path.dirname(__file__).decode('utf-8'))
MEDIA_ROOT = os.path.join(DIRNAME, 'media')
MEDIA_URL = 'http://localhost:8000/'
ADMIN_MEDIA_PREFIX = '/media/'
I have tripple checked the local_settings.py file and there is no mention of the word 'media' anywhere in it, so I'm sure there are no setting overrides.
If it helps, I'm on Windows, but I'm using all the proper unix notation for my paths.
This is a Windows only bug. I am developing a Satchmo app on Windows and it does this, but when I deploy on a Linux box it works just fine. I just go into the database and edit the paths there when I am doing testing on my Windows box.
Turns out the issue is a problem with slash directions in the settings.py file.
Usually, I create a relative_path() function in my settings.py file so I can easily set:
MEDIA_ROOT = absolute_path('media')
The version of Satchmo I was using encouraged the use of a DIRNAME setting instead:
DIRNAME = os.path.abspath(os.path.dirname(__file__).decode('utf-8')
The issue was, using this technique, my MEDIA_ROOT was being set as such:
MEDIA_ROOT = os.path.join(DIRNAME, 'media')
But this was using the Windows backslashes instead of the Unix forward slashes. I've resolve it with:
MEDIA_ROOT = os.path.join(DIRNAME, 'media').replace('\\', '/')