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

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('\\', '/')

Related

Found another file with the destination path 'admin'

I am trying to deploy the app on Heroku but when I run the following command: "python manage.py collectstatic" it returns multiple "Found another file with the destination path 'admin...".
When I "git push heroku" the app, I can see the same error.
Next, the application works, but /admin page doesn't have any format, like it is not reading css, font, etc. I've checked staticfiles/admin and it has its css,font,img and js folder with files.
I've tried all the advices given here, but I'm not finding a solution. Here my settings (see my comments at the end of the code):
import os
import django_heroku
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
.
.
.
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') #Heroku
#STATIC_ROOT = os.path.join(BASE_DIR, 'static') #ok for IBM Cloud
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(STATIC_ROOT, 'media') # if I comment this line and
MEDIA_URL = '/media/' # this line, /admin page has correct css but I don't have images in the application
# Extra places for collectstatic to find static files.(extra heroku)
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
# Next line makes application not work, it shows database errors
django_heroku.settings(locals())
"""
so, I added "release: python manage.py migrate" to procfile, now the app works,
/admin shows format ok, but database seems to be empty, no information is displayed on
site pages, and admin users don't exist anymore (my database is sqlite3).
"""
And what I get when "git push heroku master" is:
remote: Found another file with the destination path 'admin/img/selector-icons.svg'. 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.
remote: Found another file with the destination path 'admin/img/calendar-icons.svg'. 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.
.
.
.
Please help

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

Django cache. ManifestStaticFilesStorage

I have just started to use ManifestStaticFilesStorage and I am running into a problem I do not understand.
Firstly, if I prepare and run the website without ManifestStaticFilesStorage, then everything displays properly. Within the browser I can for example, see a link to an image and if I follow that it shows the image in a resource box:
Next, I add the following line of code into settings
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
and I also have:
STATIC_ROOT = os.path.join(BASE_DIR, "static")
I then delete the static directory and rebuild everything (migrations, collect static).
This produces a website with the following link to an image, but the resource is not visible:
However, when I go into the static folder in my project and look at the directory, I can see the file clearly and as far as I can tell, it appears normal:
It's like Django is failing to link up correctly when I use ManifestStaticFilesStorage.
I have included some other settings that may be relevant:
STATIC_URL = '/static/'
# STATIC_ROOT = 'static'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATICFILES_DIRS = [
'./ebdjango/static/',
]
I'm new to this, so if you have any suggestions on how to proceed with the cache in Django, please let me know.
Many thanks
Mark

Django Wagtail Deployment Static File Server

After deployment today, for some reason, the project no longer shows style from items that would have been collected during the collectstatic process. I have full access to the files from any browser. I have checked all permissions. I have browsed to the site from the development server, and other machines to eliminate software\font possibilities. No idea what's going on here.
I serve the files from a different server. Other django projects are unaffected. No other django projects use anything like wagtail though. Pulling my hair out at this point and probably just missing something simple. What am I missing?
base.py config
STATIC_ROOT = '/var/www/html/static.xxxxxx.net'
STATIC_URL = 'http://static.xxxxxx.net/'
MEDIA_ROOT = '/var/www/html/media.xxxxxx.net'
MEDIA_URL = 'http://media.xxxxxx.net/'
Checking for file existence on server:
-rw-rw-r-- 1 xxxxxx xxxxxx 13648 Aug 24 09:18 /var/www/html/static.xxxxxx.net/wagtailadmin/css/userbar.3d5222a7eba2.css
Checking CSS relative references
-rw-rw-r-- 1 xxxxxx xxxxxx 68812 Aug 24 09:18 /var/www/html/static.xxxxxx.net/wagtailadmin/css/../../wagtailadmin/fonts/opensans-regular.45f80416d702.woff2
Django Debug Toolbar shows 4 static files used for both the production and development environments. Everything is identical.
In the chrome inspect view, if I replace a relative CSS stylesheet link in the development environment with a link from the file server, it breaks the same way.
From:
/static/wagtailadmin/css/userbar.css
To:
http://static.xxxxxx.net/wagtailadmin/css/userbar.css
Again, I can stick that address in my browser, any browser, and I see the stylesheet. I really have no idea how my file server could be stopping browsers from processing CSS, but that's what it's starting to look like.
Update: in the chrome inspect view, if I remove a css reference that uses a stylesheet from my fileserver, the page loses all the style\colors\etc. If I reapply the link to my server, it applys the styles again. It seems to apply all the style except icons\glyphs.
Update 2: If I change to STATIC_URL = '/static/' I get the styles... Until I turn debug back off :-/
Wagtail's recommended setup for STATIC_ROOT, STATIC_URL, MEDIA_ROOT, and MEDIA_URL is typically much simpler and the ..._URL declarations are typically not absolute references. I set things up in base.py like this:
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [
os.path.join(os.path.join(BASE_DIR, directory_structure_down_to..., 'static'),
--- include as many lines like above as necessary here ---
]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
If you use wagtail-react-streamfield, update it. The font wagtail.woff is duplicated there and it gets picked up first (before wagtail's original one) by Django's static subsystem when collecting statics.

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

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.