Django Displaying Images Not Found
up vote
1
down vote
favorite
This has been driving me crazy for 2 days now and I cannot find an answer to this. I have looked through countless posts and cannot get this to work.
I am trying to display a profile picture for a user using Django ImageField in my model.
For some reason it keeps on coming up with 404 not found, even though I can see that the path to the image file is correct.
For example:
My model:
class KPILead(models.Model):
name = models.CharField(max_length=255)
position = models.CharField(max_length=255)
company = models.ForeignKey(KPICompany)
profile_pic = models.ImageField(upload_to='profile_pics/')
def __str__(self):
return self.name
This is indeed uploading the image file to the media/profile_pics folder in my root directory.
The view:
@login_required(login_url='/')
def eftlead_detail(request, eftlead_id):
context = dict()
context['eftlead'] = KPILead.objects.get(pk=eftlead_id)
context['team_names'] = KPITeam.objects.filter(eft_lead__id=eftlead_id)
context['incidents'] = KPIIncidentReport.objects.filter(eft_lead__id=eftlead_id)
context['image_url'] = context['eftlead'].profile_pic.url
return render(request, 'templates/eftlead.html', context)
The static and media settings in my settings file:
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
And I have added:
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
to my urls file.
It just gives an error of 404 not found, even when I check the source in Chrome or Firefox I can see that correct path is being shown. If I try and click on the image in the source to go to http://127.0.0.1:8000/media/profile_pics/default.jpg I get an error of 404 not found, so Django is clearly not finding the file even though the path is correct.
As I said I have struggling with this for 2 days now and is probably the last thing I need to finish this project off, but I cannot understand what is going wrong.
I would happy to provide further information if required and thank you for any help.
EDIT: I have included my full settings file.
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 = 'q#-jd#zkg7+#2-=6pjy(%vg-%=sh%c1*c%ypu&uxz0-4cm-9^p'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
USE_DJANGO_JQUERY = 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',
'base.apps.BaseConfig',
'projects.apps.ProjectsConfig',
'kpi.apps.KpiConfig',
'smart_selects'
]
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 = 'gregweb.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates', 'kpi'],
'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 = 'gregweb.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase'
}
}
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 = 'Africa/Johannesburg'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
LOGIN_REDIRECT_URL = '/kpi'
LOGOUT_REDIRECT_URL = '/'
python django
add a comment |
up vote
1
down vote
favorite
This has been driving me crazy for 2 days now and I cannot find an answer to this. I have looked through countless posts and cannot get this to work.
I am trying to display a profile picture for a user using Django ImageField in my model.
For some reason it keeps on coming up with 404 not found, even though I can see that the path to the image file is correct.
For example:
My model:
class KPILead(models.Model):
name = models.CharField(max_length=255)
position = models.CharField(max_length=255)
company = models.ForeignKey(KPICompany)
profile_pic = models.ImageField(upload_to='profile_pics/')
def __str__(self):
return self.name
This is indeed uploading the image file to the media/profile_pics folder in my root directory.
The view:
@login_required(login_url='/')
def eftlead_detail(request, eftlead_id):
context = dict()
context['eftlead'] = KPILead.objects.get(pk=eftlead_id)
context['team_names'] = KPITeam.objects.filter(eft_lead__id=eftlead_id)
context['incidents'] = KPIIncidentReport.objects.filter(eft_lead__id=eftlead_id)
context['image_url'] = context['eftlead'].profile_pic.url
return render(request, 'templates/eftlead.html', context)
The static and media settings in my settings file:
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
And I have added:
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
to my urls file.
It just gives an error of 404 not found, even when I check the source in Chrome or Firefox I can see that correct path is being shown. If I try and click on the image in the source to go to http://127.0.0.1:8000/media/profile_pics/default.jpg I get an error of 404 not found, so Django is clearly not finding the file even though the path is correct.
As I said I have struggling with this for 2 days now and is probably the last thing I need to finish this project off, but I cannot understand what is going wrong.
I would happy to provide further information if required and thank you for any help.
EDIT: I have included my full settings file.
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 = 'q#-jd#zkg7+#2-=6pjy(%vg-%=sh%c1*c%ypu&uxz0-4cm-9^p'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
USE_DJANGO_JQUERY = 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',
'base.apps.BaseConfig',
'projects.apps.ProjectsConfig',
'kpi.apps.KpiConfig',
'smart_selects'
]
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 = 'gregweb.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates', 'kpi'],
'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 = 'gregweb.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase'
}
}
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 = 'Africa/Johannesburg'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
LOGIN_REDIRECT_URL = '/kpi'
LOGOUT_REDIRECT_URL = '/'
python django
Possible that the file doesn't exist in your project
– Lemayzeur
Nov 22 at 5:01
Do you mean the file simply does not exist? I can see that it is in the media/profile_pics folder. That was one of the first things I checked for. But the file was uploaded to the correct folder.
– Greg Strydom
Nov 22 at 5:24
can you provide the django settings.py file, so we can have some more context.
– anurag
Nov 22 at 5:51
I have copied the entire contents of my settings file. I appreciate the help, thank you.
– Greg Strydom
Nov 22 at 6:05
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
This has been driving me crazy for 2 days now and I cannot find an answer to this. I have looked through countless posts and cannot get this to work.
I am trying to display a profile picture for a user using Django ImageField in my model.
For some reason it keeps on coming up with 404 not found, even though I can see that the path to the image file is correct.
For example:
My model:
class KPILead(models.Model):
name = models.CharField(max_length=255)
position = models.CharField(max_length=255)
company = models.ForeignKey(KPICompany)
profile_pic = models.ImageField(upload_to='profile_pics/')
def __str__(self):
return self.name
This is indeed uploading the image file to the media/profile_pics folder in my root directory.
The view:
@login_required(login_url='/')
def eftlead_detail(request, eftlead_id):
context = dict()
context['eftlead'] = KPILead.objects.get(pk=eftlead_id)
context['team_names'] = KPITeam.objects.filter(eft_lead__id=eftlead_id)
context['incidents'] = KPIIncidentReport.objects.filter(eft_lead__id=eftlead_id)
context['image_url'] = context['eftlead'].profile_pic.url
return render(request, 'templates/eftlead.html', context)
The static and media settings in my settings file:
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
And I have added:
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
to my urls file.
It just gives an error of 404 not found, even when I check the source in Chrome or Firefox I can see that correct path is being shown. If I try and click on the image in the source to go to http://127.0.0.1:8000/media/profile_pics/default.jpg I get an error of 404 not found, so Django is clearly not finding the file even though the path is correct.
As I said I have struggling with this for 2 days now and is probably the last thing I need to finish this project off, but I cannot understand what is going wrong.
I would happy to provide further information if required and thank you for any help.
EDIT: I have included my full settings file.
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 = 'q#-jd#zkg7+#2-=6pjy(%vg-%=sh%c1*c%ypu&uxz0-4cm-9^p'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
USE_DJANGO_JQUERY = 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',
'base.apps.BaseConfig',
'projects.apps.ProjectsConfig',
'kpi.apps.KpiConfig',
'smart_selects'
]
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 = 'gregweb.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates', 'kpi'],
'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 = 'gregweb.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase'
}
}
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 = 'Africa/Johannesburg'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
LOGIN_REDIRECT_URL = '/kpi'
LOGOUT_REDIRECT_URL = '/'
python django
This has been driving me crazy for 2 days now and I cannot find an answer to this. I have looked through countless posts and cannot get this to work.
I am trying to display a profile picture for a user using Django ImageField in my model.
For some reason it keeps on coming up with 404 not found, even though I can see that the path to the image file is correct.
For example:
My model:
class KPILead(models.Model):
name = models.CharField(max_length=255)
position = models.CharField(max_length=255)
company = models.ForeignKey(KPICompany)
profile_pic = models.ImageField(upload_to='profile_pics/')
def __str__(self):
return self.name
This is indeed uploading the image file to the media/profile_pics folder in my root directory.
The view:
@login_required(login_url='/')
def eftlead_detail(request, eftlead_id):
context = dict()
context['eftlead'] = KPILead.objects.get(pk=eftlead_id)
context['team_names'] = KPITeam.objects.filter(eft_lead__id=eftlead_id)
context['incidents'] = KPIIncidentReport.objects.filter(eft_lead__id=eftlead_id)
context['image_url'] = context['eftlead'].profile_pic.url
return render(request, 'templates/eftlead.html', context)
The static and media settings in my settings file:
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
And I have added:
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
to my urls file.
It just gives an error of 404 not found, even when I check the source in Chrome or Firefox I can see that correct path is being shown. If I try and click on the image in the source to go to http://127.0.0.1:8000/media/profile_pics/default.jpg I get an error of 404 not found, so Django is clearly not finding the file even though the path is correct.
As I said I have struggling with this for 2 days now and is probably the last thing I need to finish this project off, but I cannot understand what is going wrong.
I would happy to provide further information if required and thank you for any help.
EDIT: I have included my full settings file.
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 = 'q#-jd#zkg7+#2-=6pjy(%vg-%=sh%c1*c%ypu&uxz0-4cm-9^p'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
USE_DJANGO_JQUERY = 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',
'base.apps.BaseConfig',
'projects.apps.ProjectsConfig',
'kpi.apps.KpiConfig',
'smart_selects'
]
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 = 'gregweb.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates', 'kpi'],
'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 = 'gregweb.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase'
}
}
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 = 'Africa/Johannesburg'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
LOGIN_REDIRECT_URL = '/kpi'
LOGOUT_REDIRECT_URL = '/'
python django
python django
edited Nov 22 at 6:04
asked Nov 22 at 4:54
Greg Strydom
369
369
Possible that the file doesn't exist in your project
– Lemayzeur
Nov 22 at 5:01
Do you mean the file simply does not exist? I can see that it is in the media/profile_pics folder. That was one of the first things I checked for. But the file was uploaded to the correct folder.
– Greg Strydom
Nov 22 at 5:24
can you provide the django settings.py file, so we can have some more context.
– anurag
Nov 22 at 5:51
I have copied the entire contents of my settings file. I appreciate the help, thank you.
– Greg Strydom
Nov 22 at 6:05
add a comment |
Possible that the file doesn't exist in your project
– Lemayzeur
Nov 22 at 5:01
Do you mean the file simply does not exist? I can see that it is in the media/profile_pics folder. That was one of the first things I checked for. But the file was uploaded to the correct folder.
– Greg Strydom
Nov 22 at 5:24
can you provide the django settings.py file, so we can have some more context.
– anurag
Nov 22 at 5:51
I have copied the entire contents of my settings file. I appreciate the help, thank you.
– Greg Strydom
Nov 22 at 6:05
Possible that the file doesn't exist in your project
– Lemayzeur
Nov 22 at 5:01
Possible that the file doesn't exist in your project
– Lemayzeur
Nov 22 at 5:01
Do you mean the file simply does not exist? I can see that it is in the media/profile_pics folder. That was one of the first things I checked for. But the file was uploaded to the correct folder.
– Greg Strydom
Nov 22 at 5:24
Do you mean the file simply does not exist? I can see that it is in the media/profile_pics folder. That was one of the first things I checked for. But the file was uploaded to the correct folder.
– Greg Strydom
Nov 22 at 5:24
can you provide the django settings.py file, so we can have some more context.
– anurag
Nov 22 at 5:51
can you provide the django settings.py file, so we can have some more context.
– anurag
Nov 22 at 5:51
I have copied the entire contents of my settings file. I appreciate the help, thank you.
– Greg Strydom
Nov 22 at 6:05
I have copied the entire contents of my settings file. I appreciate the help, thank you.
– Greg Strydom
Nov 22 at 6:05
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Add this in your project's urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) #not both
Thank you! I had the +static in my APPS urls.py. It needs to be in the projects urls.py. Thank you so much this has been driving me mad for a long time!
– Greg Strydom
Nov 22 at 6:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424109%2fdjango-displaying-images-not-found%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Add this in your project's urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) #not both
Thank you! I had the +static in my APPS urls.py. It needs to be in the projects urls.py. Thank you so much this has been driving me mad for a long time!
– Greg Strydom
Nov 22 at 6:41
add a comment |
up vote
2
down vote
accepted
Add this in your project's urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) #not both
Thank you! I had the +static in my APPS urls.py. It needs to be in the projects urls.py. Thank you so much this has been driving me mad for a long time!
– Greg Strydom
Nov 22 at 6:41
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Add this in your project's urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) #not both
Add this in your project's urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) #not both
answered Nov 22 at 6:31
Bidhan Majhi
394212
394212
Thank you! I had the +static in my APPS urls.py. It needs to be in the projects urls.py. Thank you so much this has been driving me mad for a long time!
– Greg Strydom
Nov 22 at 6:41
add a comment |
Thank you! I had the +static in my APPS urls.py. It needs to be in the projects urls.py. Thank you so much this has been driving me mad for a long time!
– Greg Strydom
Nov 22 at 6:41
Thank you! I had the +static in my APPS urls.py. It needs to be in the projects urls.py. Thank you so much this has been driving me mad for a long time!
– Greg Strydom
Nov 22 at 6:41
Thank you! I had the +static in my APPS urls.py. It needs to be in the projects urls.py. Thank you so much this has been driving me mad for a long time!
– Greg Strydom
Nov 22 at 6:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424109%2fdjango-displaying-images-not-found%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible that the file doesn't exist in your project
– Lemayzeur
Nov 22 at 5:01
Do you mean the file simply does not exist? I can see that it is in the media/profile_pics folder. That was one of the first things I checked for. But the file was uploaded to the correct folder.
– Greg Strydom
Nov 22 at 5:24
can you provide the django settings.py file, so we can have some more context.
– anurag
Nov 22 at 5:51
I have copied the entire contents of my settings file. I appreciate the help, thank you.
– Greg Strydom
Nov 22 at 6:05