I have uwsgi and django.
Now I want to use uwsgi without nginx
So,I would like to use static from uwsgi even when DEBUG is false.
My static setting is like this ,and
STATIC_ROOT = 'static'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR,'frontend/dist'),
)
pytohn manage.py collectstatic.
Every static files are gathered under static folder.
Then I tryied some options to start uwsgi.
uwsgi --http :8008 --module myapp.wsgi --process=1
uwsgi --http :8008 --module myapp.wsgi --process=1 --check-static=/static
uwsgi --http :8008 --module myapp.wsgi --process=1 --static-map=/static
However I can't load the images under static folder.
such as
https://www.myapp.com/static/defapp/test.img
There is a image under /static/defapp/test.img.
How can I fix this?
put this path for static
import os
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
insted of
STATICFILES_DIRS = (
os.path.join(BASE_DIR,'frontend/dist'),
)
Related
On a new installation of windows 10, right after installing python v3.9.5, I do:
>pip install django
>django-admin startproject test1
>cd test1
>python manage.py migrate
And then I edit test1/settings.py only to set the STATIC_ROOT and disable DEBUG mode
settings.py
import os
...
DEBUG = False
ALLOWED_HOSTS = ['127.0.0.1']
...
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
And then:
>python manage.py collectstatic
>python manage.py runserver
And finally, I navigate to http://127.0.0.1:8000/admin/ and I see this:
I have deployed by Django project as a Heroku app, but can not get the static files to work.
settings.py
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = 'static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
which is exactly what is recommended at Django and Static Assets
I have set DISABLE_COLLECTSTATIC to false with,
$ heroku config:set DISABLE_COLLECTSTATIC=0 --app mathsproject
The file system looks like this,
which shows that the 'static' directory is in the root of my Django project. But I do not see where the 'staticfiles' directory is? Should this be created somewhere?
When running,
$ heroku logs
I typically get errors showing that the static files are missing. And this is obvious in the browser too.
......
2016-07-11T07:39:30.187273+00:00 app[web.1]: Not Found: /static/assets/js/jquery-1.10.2.min.js
2016-07-11T07:39:30.264037+00:00 app[web.1]: Not Found: /static/assets/img/4.png
2016-07-11T07:39:30.283627+00:00 app[web.1]: Not Found: /static/assets/img/testimonials/1.jpg
........
Whitenoise has been enabled by adding, to mathProject/wsgi.py
import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mathsProject.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
To the bottom of settings.py I put
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
Running
$ heroku run bash
and then,
$ python manange.py collectstatic --noinput
this gives several lines of errors, the last of which is,
OSError: [Errno 2] No such file or directory: '/app/mathsProject/static'
But there is a 'static' directory in 'mathsProject'
Thanks,
The static files are recognised when the 'static' directory is inside the Django project directory, which unfortunately had the same name as the whole Django directory. Both were called 'mathsProject'.
Also I set,
$ heroku config:set DISABLE_COLLECTSTATIC=1
This works for me.
My question is :
When i run collectstatic command staticfiles on heroku server my app didn't copied my staticfiles ?
my configuration :
**BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))**
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_in_env","static_root")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static_in_pro","our_static"),
Django takes the static files from STATICFILES_DIRS and static folders inside installed apps into STATIC_ROOT.
You should check for sure that you have your static files inside your folder: BASE_DIR/static_in_pro/our_static.
The simplest way is to create a static folder inside your app and than put your static files inside it . In this case, you can ignore STATICFILES_DIRS.
I'm having trouble showing my CSS/Static files on my django app I just deployed on Heroku. It doesn't show any debugging errors, so I don't know where to start.
Here is my code:
SETTINGS_DIR = os.path.dirname(__file__)
PROJECT_PATH = os.path.join(SETTINGS_DIR, os.pardir)
PROJECT_PATH = os.path.abspath(PROJECT_PATH)
STATIC_PATH = os.path.join(PROJECT_PATH, 'static')
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
STATIC_PATH,
)
Used WhiteNoise to collectstaticfiles. Thanks for helping.
https://devcenter.heroku.com/articles/django-assets for documentation.
Try setting an absolute path to your STATIC_ROOT. From Django documentation: Settings:
STATIC_ROOT
The absolute path to the directory where collectstatic will collect static files for deployment.
Then make sure that you run collectstatic.
Last, I usually set STATICFILES_DIRS to None for deployment.
When i try to load my staticfiles from my
/static/
folder to heroku with
heroku run python manage.py loadstatic
i get the following error:
OSError: [Errno 2] No such file or directory: '/app/hellodjango/static'
my setting file has this part
# Static asset configuration
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/
# Additional locations of static files
STATICFILES_DIRS = (
('assets', "/home/ikke/hellodjango/static"),
)
Where do i go wrong? cause obvious the path it tries to load from is wrong. heroku uses django 1.6 and i used 1.5 before