I have this model Blog and using it in 'blog' subdomain created with 'django-hosts'.
My subdomains in 'hosts.py':
from django.conf import settings
from django_hosts import patterns, host
host_patterns = patterns('',
host(r'blog', 'blog.urls', name='blog'),
host(r'(|www)', settings.ROOT_URLCONF, name='www'),
)
And Blog model - Note that 'title_image' field powered by 'sorl.thumbnail' and 'content' field is a 'django-ckeditor' uploadable field:
class Blog(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL,
verbose_name=_('author'),
on_delete=models.CASCADE,
related_name='blog_author')
title = models.CharField(verbose_name=_('title'), max_length=200)
title_image = ImageField(verbose_name=_('title image'), blank=True)
content = RichTextUploadingField(verbose_name=_('content'))
I've' created a simple ListView for blog that show every blog title, content and title_image to viewer:
class BlogListView(ListView):
"""Everyone can see all blogs"""
template_name = 'blog/templates/blog/blog_list_view.html'
model = Blog
context_object_name = 'blogs'
And my blog.urls:
from django.urls import path
from . import views
app_name = 'blog'
urlpatterns = [
path('', views.BlogListView.as_view(), name='blog_list_view'),
]
When I'm using my blog subdomain (eg: blog.localhost:8000/) it doesn't show any image to me whether it's the title_image or any image in django-ckeditor powered 'content' field. But when I'm not using subdomain and instead use 'blog' app as other 'URLCONF' path (eg: localhost:8000/blog/) I can see every images without any problem. Anyone knows why using subdomains, media files does not shown and how to fix it?