Django hosting static files on the server -
i trying deploy django project on server. but, when use it, static file on django can not read correctly
i deploy project on debian server. static file of course in same server, have succeeded in deploying project. static files css still can not appear in project
this settings files:
""" django settings akun project. more information on file, see https://docs.djangoproject.com/en/1.7/topics/settings/ full list of settings , values, see https://docs.djangoproject.com/en/1.7/ref/settings/ """ # build paths inside project this: os.path.join(base_dir, ...) import os project_root = os.path.abspath(os.path.dirname(__file__)) project_dir = os.path.join(project_root) # quick-start development settings - unsuitable production # see https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ # security warning: keep secret key used in production secret! secret_key = '8g*v#sf1i0y#+@5jyy$kk)wlixu*9yo(t$&1n%59ip*391sy@u' # security warning: don't run debug turned on in production! debug = true template_debug = true allowed_hosts = [] # application definition installed_apps = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'simofa', 'accounts', ) middleware_classes = ( 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.common.commonmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.auth.middleware.sessionauthenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'django.middleware.clickjacking.xframeoptionsmiddleware', ) root_urlconf = 'akun.urls' wsgi_application = 'akun.wsgi.application' # database # https://docs.djangoproject.com/en/1.7/ref/settings/#databases databases = { 'default': { 'engine': 'django.db.backends.mysql', 'name': 'pgina', 'user': 'root', 'password': '123', 'host': 'localhost', # or ip address db hosted on 'port': '3306', } } # internationalization # https://docs.djangoproject.com/en/1.7/topics/i18n/ language_code = 'en-us' time_zone = 'asia/jakarta' use_i18n = true use_l10n = true use_tz = true # static files (css, javascript, images) # https://docs.djangoproject.com/en/1.7/howto/static-files/ static_url = '/static/' # template location template_dirs = ( os.path.join(os.path.dirname(project_root), "static", "templates"), '/home/boss/kantor/akun/templates/', ) if debug: media_url = '/media/' static_root = os.path.join(os.path.dirname(project_dir),"static","static-only") media_root = os.path.join(os.path.dirname(project_dir),"static","media") staticfiles_dirs = os.path.join(os.path.dirname(project_dir),"static","static"),
i'm trying change static_url='/static/'
url static_url='http://www.url.com/my_project/static'
result still doesn't appears
when try in localhost, works properly.
how solution ?
in production need first define static_root
, run collectstatic
in order have static files collected there.
after running collectstatic
should able cd dir associated static_root
, see files.
edit: code below should added in apache conf file, not in django settings
finally if using apache (and serving files same server running django app) need serve path of static_root
under url defined in static_url
, example assuming static_url
/static/:
alias /static/ /path/to/mysite.com/static_root_directory/
and set permissions:
<directory /path/to/mysite.com/static_root_directory> require granted </directory>
ps didn't provide many details environment (server, static on same server or not) had make assumptions. if provide more details i'm happy help.
Comments
Post a Comment