I'm getting a 400 error when trying to access the /admin/filebrowser/browse/ page. I followed the instructions as per https://django-filebrowser.readthedocs.org/en/3.5.2/quickstart.html and have my URLs and installed apps configured correctly.
What I'm not too sure about are the media paths in settings.py;
FILEBROWSER_DIRECTORY = os.path.join(BASE_DIR, '/ogencat/MEDIA/uploads')
FILEBROWSER_MEDIA_ROOT = os.path.join(BASE_DIR, '/ogencat/MEDIA')
FILEBROWSER_MEDIA_URL = '/MEDIA/'
I have folder in my workspace called MEDIA and a folder within called uploads.
I wasn't too sure about what the docs wanted me to do in terms of setting these paths - I hadn't seen the getattr(settings, "FILEBROWSER_MEDIA_ROOT", settings.MEDIA_ROOT) syntax before so I just added the paths as I have done for the rest of settings.py
Thanks!
You need to add trailing slashes
Directories must exist prior accessing them
Related
(Django 2.0, Django Rest Framework 3.8, Python 3.6, Django Storages 1.7, Dropbox 9.1)
I'm trying to upload a file to the Dropbox App Folder I've created, but I run into the same error at every attempt:
C:/TrainerPics/UI_4.png' did not match pattern '(/(.|[\r\n])*|id:.*)|(rev:[0-9a-f]{9,})|(ns:[0-9]+(/.*)?)'
On the Dropbox dashboard from desktop, the folder I want to upload to is shown as:
Dropbox > Apps > DjangoAppNameHere
Here's my setup in settings.py:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
DEFAULT_FILE_STORAGE = 'storages.backends.dropbox.DropBoxStorage'
DROPBOX_OAUTH2_TOKEN = 'some_token_here'
where storages is also listed in installed apps. Here's the model field I'm trying to upload:
trainer_profile_pic = models.ImageField(upload_to="TrainerPics/", null=True, blank=True)
I've tried this both with and without the / character, and tried this using upload_to=DjangoAppNameHere both with FileField and ImageField with no success. The documentation for Dropbox is rather sparse in the django-storages package, and doesn't describe how to set up a field to get it working.
That error message is coming from the Dropbox API, and it's indicating that the supplied path doesn't match the expected format. That is, when uploading to Dropbox via the Dropbox API, you're expected to supply the desired path for the uploaded file, in a format that matches the supplied pattern.
The most commonly used format for that is the first portion of that pattern, which is just a "/"-delimited path for the remote path relative to the root in Dropbox. For example: '/TrainerPics/UI_4.png'.
Based on the output, you're instead supplying a path that looks like a local Windows filesystem path: 'C:/TrainerPics/UI_4.png'.
You'll need to update the app/configuration to supply the remote path instead.
This is an old question, just to help people who might have similar problems.
There are two options that I used.
Use a linux machine when uploading your files. This will allow the API to upload your image as it's probably the same filesystem as their servers.
Only use the DROPBOX API on the server, and use local filestorage on local development. Servers run on unix and it does not produce the error.
trying to deploy my app to uwsgi server
my settings file:
STATIC_ROOT = "/home/root/djangoApp/staticRoot/"
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/home/root/djangoApp/static/',
]
and url file:
urlpatterns = [
#urls
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
and if I try to execute the command:
python manage.py collectstatic
Then some files are okay ( admin files ), but I see an error next to files from static folder. The error is like:
Found another file with the destination path 'js/bootstrap.min.js'. It
will be ignored since only the first encountered file is collected. If
this is not what you want, make sure every static file has a unique
path.
and have no idea what can I do to solve it.
Thanks in advance,
The two paths you have in STATICFILES_DIRS are the same. So Django copies the files from one of them, then goes on to the second and tries to copy them again, only to see the files already exist.
Remove one of those entries, preferably the second.
do you have more than one application?
If so, you should put any file on a subdirectory with a unique name (like the app name for example).
collectstatic collects files from all the /static/ subdirectories, and if there is a duplication, it throw this error.
Was looking for a Python package for Django to manage assets, using Sass to compile CSS, and also cache busting, and Django-Assets / Webassets was recommended. Having trouble getting it setup though with my directory structure.
By default it looks for assets.py in each installed app. I want to set it up so that it sits in the same directory as settings.py and compiles app specific assets from each app directory into /static/js and /static/css.
I have django_assets in INSTALLED_APPS. According to the docs it looks like I needed to add this to settings.py:
ASSETS_MODULES = [
'project_dir',
]
Or:
ASSETS_MODULES = [
os.path.join(BASE_DIR, 'project_dir'),
]
Or:
ASSETS_MODULES = [
PROJECT_ROOT
]
At any rate, it just returns No asset bundles were found. If you are defining assets directly within your template, you want to use the --parse-templates option.
Even moving the assets.py into one of the app directories, it is looking in BASE_DIR/scripts which is where I keep my manage.py. Again, changing ASSETS_ROOT doesn't really same to be doing anything.
~/portal-client
project_dir
apps
account
templates
account
login.html
forms.py
urls.py
views.py
home
templates
home
home.html
urls.py
views.py
results
assets.py
settings.py
urls.py
scripts
manage.py
static
templates
base.html
footer.html
title.html
Couple of quick notes, for ASSETS_MODULES, the key word is additional:
django-assets will automatically look for assets.py files in each application, where you can register your bundles. If you want additional modules to be loaded, you can define this setting. It expects a list of importable modules:
i.e., we only use ASSETS_MODULES if we have assets.py files outside of any application. In your case, we will only specify this if project_dir is not an INSTALLED_APP.
Second, when using ASSETS_MODULES, you specify a dotted module path, not a directory. In your case, this would be project_dir.assets only if project_dir is not already part of INSTALLED_APPS.
I have installed Django file browser and added grappelli and filebrowser to my installed apps. And did every thing said in documention but when I browse http://127.0.0.1:8000/admin/filebrowser/ I got 404 page not found error. What's the problem? I configured my media settings like this:
# Media files
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/admin/'
FILEBROWSER_DIRECTORY = '/media/'
The problem is your FILEBROWSER_DIRECTORY setting. It should have absolute path.
Unfortunately, the error is hidden by the nasty 400 Bad Request, as explained in this ticket.
Just solved the exact same problem, and it's the oldest one in the book: permissions
(facepalm)
make sure your media dir is chmod-ed to 755
create media/uploads dir and also chmod it to 755
In settings.py, I don't use the FILEBROWSER_DIRECTORY (I guess that uploads is the default)
I really think that throwing 400 Bad Request is utterly useless and anoying, but oh well...
Just a related note: I don't think there is anything at /admin/filebrowser/, it just gives me a 404. Please correct me it I'm missing something here :)
I am using ADL LRS to setup a LRS(Learning Record Store) system for my own use. It uses TIN CAN API. I am using ubuntu server
As the documentation states, For the setup of LRS, I need to install django adn set it up for LRS. The adl_lrs folder inside the ADL_LRS contains the setting file for django(settings.py). I am bit new to django, so I can not fully understand the meaning of this part of the file-
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = '/var/www/adllrs/media/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://my-site-name.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
It states-
1. MEDIA_ROOT = '/var/www/adllrs/media/' which I assume it means is to put the media files like songs and videos, at this location
2. STATIC_ROOT = '' which I assumes means the path of the static directory which contains the HTML, CSS, js files.
On cloning the git, I setup the LRS, which by the way started but all the CSS broken. I looked into DOM inspector, where the link of CSS files are like-
http://my-site-name.com:8000/static/admin/css/base.css
When I visited the above url to see what's happening, I got following output as HTML(same as I get when visiting homepage, i.e http://my-site-name.com:8000)-
Page not found (404)
Request Method: GET
Request URL: http://my-site-name.com:8000/
Using the URLconf defined in adl_lrs.urls, Django tried these URL patterns, in this order:
^XAPI/
^xapi/
^admin/
The current URL, , didn't match any of these.
My urls.py looks like-
url(r'^XAPI/', include('lrs.urls')),
url(r'^xapi/', include('lrs.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls))
Obviously I am not mentioning my home page in the urls.py which point to the error. So where should I put the CSS,JS files to get the broken CSS fixed and make a default home page for this? and also I have tried to send tin can statements from wordpress, but I could not get the statements on my server. can anyone tell me how to setup a proper ADL LRS on ubuntu.
PS- Do not tell me to read the documentation as I have done it like dozen times. Tell me where I am wrong in implementing the documentation.
It sounds like you have the LRS running with just gunicorn. gunicorn by itself doesn't serve static files like the JS and CSS. I found another SO page talking about serving static files with gunicorn: https://stackoverflow.com/a/12801140/1187723
As for the LRS, when I am developing and testing locally I run Django's test server, which will deliver static files. From the project's root directory ADL_LRS, start it with python manage.py runserver. https://docs.djangoproject.com/en/1.4/ref/django-admin/#runserver-port-or-address-port
When we deploy the LRS at https://lrs.adlnet.gov/xapi/ we use nginx, which is configured to serve the static files. We have some initial set up stuff about it at https://github.com/adlnet/ADL_LRS/wiki/Using-Nginx-for-Production