By using gunicorn without nginx from digitalcloud tutorial
my server is runing and on the console is
not found: /static/style.css
settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
I already tried to
collectstatic
do urlpatterns += staticfiles_urlpatterns() in urls.py file
makemigrations + migrate
maybe django try read 'static//static/style.css' but you need this: 'style.css' ;) ?
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
urlpatterns = [your urls here] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
You can create in your project folder settings then in them create settings files like names:
local.py
from my_project.settings import *
DEBUG = True
ALLOWED_HOSTS = []
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
this run in VM like: python manage.py runserver --settings settings.local
remember in urls add:
if settings.DEBUG == True:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
web.py
from my_project.settings import *
DEBUG = False
ALLOWED_HOSTS = ["www.side.com", "side.com"]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
and then in gunicorn import only web.py file project to read in nginx
this run in VPS server.
Related
urlpatterns = [some_urls] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
statics configured
DEBUG = TRUE
python manage.py collectstatic did 1000 times
cache cleared
I have no idea what to do, can anyone help me please
I have modified my Geonode project, which is a GeoDjango project, to enable multi-tenancy using django-tenants. I am currently not able to view my thumbnails due to broken routing...
How do I correctly route my generated thumbnails like this: http://d3.demo.com(current_tenant_domain_url)/uploaded/d3(tenant)/thumbs/document-8a72dc8c-0151-11eb-a488-1062e5032d68-thumb.png
The thubnail url that is currently generated is as follows: http://localhost:8000/uploaded/thumbs/document-fcdea3a4-015c-11eb-a488-1062e5032d68-thumb.png?v=c1855f6a
urls.py
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.LOCAL_MEDIA_URL,
document_root=settings.MEDIA_ROOT)
My current settings.py
MEDIA_ROOT = os.getenv('MEDIA_ROOT', os.path.join(PROJECT_ROOT, MEDIAFILES_LOCATION))
MEDIA_URL = os.getenv('MEDIA_URL', '%s/%s/%s/' % (FORCE_SCRIPT_NAME, MEDIAFILES_LOCATION, MULTITENANT_RELATIVE_MEDIA_ROOT))
Any help will be appreciated
settings.py
MIDDLEWARE = [
'django_tenants.middleware.main.TenantMainMiddleware'
]
DATABASE_ROUTERS = (
'django_tenants.routers.TenantSyncRouter',
)
STATIC_URL = '/static/'
STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
MEDIA_URL = '/media/'
DEFAULT_FILE_STORAGE = 'django_tenants.files.storages.TenantFileSystemStorage'
MEDIA_ROOT = os.path.join(BASE_DIR, 'public', 'media')
urls.py
urlpatterns = [...] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
settings.py
STATICFILE_DIRS = [os.path.join(
BASE_DIR, 'build/static')]
STATICFILES_STORGE =
"whitenoise.storage.CompressedManifestStaticFilesStorage"
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media/images")
WHITENOISE_ROOT = os.path.join(BASE_DIR, "media")
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
# from whitenoise.django import DjangoWhiteNoise
from whitenoise import WhiteNoise
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dj_gmc.settings')
application = get_wsgi_application()
# application = DjangoWhiteNoise(application)
application = WhiteNoise(application, root='build/static')
application.add_files('build', prefix='more-files/')
application.add_files('media', prefix='more-files/')
can't find a image source it's work in normal localhost prefect
but in deploy all images gone until the frontend image
The problem has been solved after many searches and this solution if someone is interested
settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'build/static'),
os.path.join(BASE_DIR, 'build/media'),
os.path.join(BASE_DIR, 'media/images')
)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
importent urls.py
from django.views.static import serve
re_path(r'^static/(?P<path>.*)$', serve,
{'document_root': settings.STATIC_ROOT}),
re_path(r'^media/(?P<path>.*)$', serve, {
"document_root": settings.MEDIA_ROOT
})
I'm working with this website http://fotokluczniok.pl/ now.
If You press F12 You will see the staticfiles do not work correctly.
Here is my seetings.py code:
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
'/home/fotoklu/fotokluczniok/static/',
]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
Here is urls.py code:
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Project structure: CLICK HERE
How to solve this problem ?
I think you don't need to change something about the static files in the urls.py file. And also delete the variable STATIC_ROOT. In general your code in Settings.py file:
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join (BASE_DIR, 'static'),
]
I also had this problem. It helped me.
NOTE: Always restart the server after changes in settings.py
I'm deploying a Django application on heroku.
In my settings module, I have configured to host static files like
STATIC_ROOT = os.path.join(BASE_DIR, 'static_my_project')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static_my_project')
]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static_cdn', 'media_root')
and urls.py
urlpatterns = urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
But on deployment to heroku, it gives error as
SystemCheckError: System check identified some issues:
ERRORS:
?: (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.
may be help this.
STATIC_URL = '/static/'
if not DEBUG:
STATIC_ROOT = ''
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static/'),
]
The problem is in the STATIC_ROOT and STATICFILES_DIRS there names cant be same.
static root is used for collectstatic command of django.
You can remove it if not using it.
And can also remove static files dirs if not changing its default position(inside django app) to somewhere else like base or something.