Some confusion about static files (Python 3.6 Django 2.. IIS 8.5) My static files from site are found but the static files from the app are not found.
JavaScript
x
4
1
GET http://127.0.0.1:81/static/css/pyapp.css 404 (Not Found)
2
3
<link rel="stylesheet" type="text/css" href="{% static 'css/pyapp.css' %}">
4
I tried to add
JavaScript
1
2
1
STATICFILES_DIRS =[(os.path.join(BASE_DIR, 'pyapp/static')),]"<
2
to the settings.py but did not help.
Do I have to add a web.config also in the app static like in the site static folder?
JavaScript
1
16
16
1
├───pyapp
2
│ ├───migrations
3
│ │ └───__pycache__
4
│ ├───static
5
│ │ └───css
6
| │ │ └───pyapp.css <=== this is not found
7
│ ├───templates
8
│ │ └───pyapp
9
| │ │ └───my.html <=== this works
10
│ └───__pycache__
11
└───pyweb
12
├───static <=== this works
13
│ └───admin
14
│
15
└───__pycache__
16
For IIS configuration i used this tutorial: http://blog.mattwoodward.com/2016/07/running-django-application-on-windows.html
settings.py
JavaScript
1
117
117
1
import os
2
3
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
4
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
5
6
7
# Quick-start development settings - unsuitable for production
8
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
9
10
# SECURITY WARNING: keep the secret key used in production secret!
11
SECRET_KEY = '...'
12
13
# SECURITY WARNING: don't run with debug turned on in production!
14
DEBUG = True
15
16
ALLOWED_HOSTS = []
17
18
19
# Application definition
20
21
INSTALLED_APPS = [
22
'pyapp.apps.PyappConfig',
23
'django.contrib.admin',
24
'django.contrib.auth',
25
'django.contrib.contenttypes',
26
'django.contrib.sessions',
27
'django.contrib.messages',
28
'django.contrib.staticfiles',
29
]
30
31
MIDDLEWARE = [
32
'django.middleware.security.SecurityMiddleware',
33
'django.contrib.sessions.middleware.SessionMiddleware',
34
'django.middleware.common.CommonMiddleware',
35
'django.middleware.csrf.CsrfViewMiddleware',
36
'django.contrib.auth.middleware.AuthenticationMiddleware',
37
'django.contrib.messages.middleware.MessageMiddleware',
38
'django.middleware.clickjacking.XFrameOptionsMiddleware',
39
]
40
41
ROOT_URLCONF = 'pyweb.urls'
42
43
TEMPLATES = [
44
{
45
'BACKEND': 'django.template.backends.django.DjangoTemplates',
46
'DIRS': [],
47
'APP_DIRS': True,
48
'OPTIONS': {
49
'context_processors': [
50
'django.template.context_processors.debug',
51
'django.template.context_processors.request',
52
'django.contrib.auth.context_processors.auth',
53
'django.contrib.messages.context_processors.messages',
54
],
55
},
56
},
57
]
58
59
WSGI_APPLICATION = 'pyweb.wsgi.application'
60
61
62
# Database
63
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
64
65
DATABASES = {
66
'default': {
67
'ENGINE': 'django.db.backends.sqlite3',
68
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
69
}
70
}
71
72
73
# Password validation
74
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
75
76
AUTH_PASSWORD_VALIDATORS = [
77
{
78
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
79
},
80
{
81
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
82
},
83
{
84
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
85
},
86
{
87
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
88
},
89
]
90
91
92
# Internationalization
93
# https://docs.djangoproject.com/en/2.0/topics/i18n/
94
95
LANGUAGE_CODE = 'de-ch'
96
97
TIME_ZONE = 'Europe/Berlin'
98
99
USE_I18N = True
100
101
USE_L10N = True
102
103
USE_TZ = True
104
105
106
# Static files (CSS, JavaScript, Images)
107
# https://docs.djangoproject.com/en/2.0/howto/static-files/
108
109
STATICFILES_FINDERS = (
110
'django.contrib.staticfiles.finders.FileSystemFinder',
111
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
112
)
113
114
STATIC_URL = '/static/'
115
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
116
STATICFILES_DIRS =[(os.path.join(BASE_DIR, 'pyapp/static')),]
117
Advertisement
Answer
I found the Problem. Thx for help!
I don’t understand why IIS is not refreshing the VirtualDirectory. I refreshed x times the website and restarted it. But the pyapp folder in static was not visible until i set the physical path again.
JavaScript
1
8
1
sites
2
├───pyweb
3
| └───pyapp
4
| └───pyweb
5
| └───static
6
| | └───admin
7
| | └───pyapp <=== this was not visible in IIS, refreshing not enough!
8
Is this a bug or should I know this?