Hello
My application works pretty well with DEBUG = True.
and when I change the DEBUG to False only pages and data from SQLite works.
no files, images, and styles works.
for example the excel file:
Hello
My application works pretty well with DEBUG = True.
and when I change the DEBUG to False only pages and data from SQLite works.
no files, images, and styles works.
for example the excel file:
Is this the same issue as what you’re describing here? (Deploy Django with Apache and mod_wsgi) If so, there’s no need to open up new conversations for it. Further discussion can continue there.
it is not the same, the other were about Apache and it finished by this.
I’d answered and found the solution of the Apache issue and this is another issue.
All my best
Ok, so then to address this, we’ll need to see your settings.py file for this application, along with whatever server configuration components being used. (Is this also Apache?)
Note: Having DEBUG=True changes many things within Django regarding file handling - getting different results with changing DEBUG=True to DEBUG=False is expected.
It may help for you to review the docs on:
it is not with Apache just I run it python manage.py runserver
and this is my settings.py:
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '$si5l1gh!d1mh=ksix($j7lklc%)qdl21chyfye1$%g#)3n4sv'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['localhost','127.0.0.1','10.3.6.38']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Home',
'user',
'crispy_forms',
'django_filters',
'mathfilters',
'ckeditor',
'rest_framework',
'import_export',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'WikiPed.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'WikiPed.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/Home/static/'
STATICFILES_DIRS =[
os.path.join(BASE_DIR,'Home/static/'),]
TEMPLATE_DIRS = (os.path.join(BASE_DIR, '/Home/templates/'),)
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'Home/static')
print(BASE_DIR)
CRISPY_TEMPLATE_PACK='bootstrap4'
LOGIN_REDIRECT_URL='EnentWorkOver'
LOGIN_URL ='login'
MEDIA_ROOT =os.path.join(BASE_DIR,'media/')
MEDIA_URL = '/media/'
#SMTP Configuration
#EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'XXXXXXXXX@gmail.com'
EMAIL_HOST_PASSWORD = "XXXXXXXX"
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH =os.path.join(BASE_DIR,"media/sent_mails/")
DEFAULT_FROM_EMAIL="WikiPED <XXXXXXXXX@gmail.com>"
and this is my urls.py
from django.contrib import admin
from django.urls import path , include
from Home import views
from django.conf.urls.static import static
from django.conf import setting
from user import views as Userviews2
from django.contrib.auth import views as auth_views
from django.conf.urls import url
import os
handler404 = 'tutorial.views.custom_404'
urlpatterns = [
path('', views.Home, name='WikiPED'),
path('admin/', admin.site.urls),
path('About/', views.about ,name='AboutWiki'),
path('register/', Userviews2.register ,name='register'),
path('login/', Userviews2.login_user ,name='login'),
path('logout/', Userviews2.logout_user ,name='logout'),
path('forbidden/', Userviews2.permission ,name='Permission'),
path('Notes/', Userviews2.AutoComplet ,name='Autofield'),
path('Div_EP/', views.Div_EP ,name='Div_EP'),
path('Scheduling/', views.Scheduling ,name='Scheduling'),
path('Add_Contrat/', views.Contratadd.as_view(), name='Add_Contrat'),
path('Up_Contrat/<slug:pk>/update/', views.ContratUpadtW.as_view(), name='Up_Contrat'),
path('dlt_Contrat/<slug:pk>/delete/', views.Contratdlt.as_view(), name='dlt_Contrat'),
path('Contrat_detail/<int:id_itm>/', views.Contrat_detail, name='Contrat_detail'),
] + static(settings.MEDIA_URL , document_root=settings.MEDIA_ROOT)
See the --insecure parameter of the runserver command and Serving files uploaded by a user during development - particularly the green note at the bottom of that section.
I solved a half of the issue and I can download the files by adding this code in urls.py
from django.views.static import serve
urlpatterns = [
url(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT, }),
...
]
but the styling still doesn’t work correctly!