Greetings, fellow humans

I have been on this issue for a couple days and would really appreciate some help. So I successfully deployed my app and everything works fine including css and the javascript except for this little thing which Im sure is just a little fix i am missing, resulting to my uploaded images not displaying even tho i see the “upload successful” page.

My image model

class Image(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL,
                             related_name='images_created')
    title = models.CharField(max_length=2000)
    slug = models.SlugField(max_length=200,
                            blank=True)
    url = models.URLField()
    image = models.ImageField(upload_to='/home/kingiyk/stylplus/media/')
    description = models.TextField(blank=True, null=True)
    created = models.DateField(auto_now_add=True,
                                                db_index=True)
    users_like = models.ManyToManyField(settings.AUTH_USER_MODEL,
                                                    related_name='images_liked', blank=True)

    tags = TaggableManager()

    class Meta:
        ordering = ('-created',)




    def __str__(self):
        return self.title


    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.title)
            super(Image, self).save(*args, **kwargs)

    def get_absolute_url(self):
        return reverse('images:detail', args=[self.id, self.slug])

my nginx conf

server {
    listen 80;
    server_name 67.207.87.22;

    location = /favicon.ico { access_log off; log_not_found off;

    }

    location /static/ {
        alias /home/kingiyk/stylplus/static;
    }

    location /media/ {
        alias /home/kingiyk/stylplus/media;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/kingiyk/stylplus/stylplus.sock;
    }
}

my uploaded images are located in /home/kingiyk/stylplus/media/ so atleast i know they were saved.

here is my settings file:

"""
Django settings for stylplus project.

Generated by 'django-admin startproject' using Django 1.8.6.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# BASE_DIR =
# os.path.dirname(os.path.dirname(os.path.abspath(os.path.join(__file__,
# os.pardir))))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/



# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['67.207.87.22', 'styllplus.com', 'www.styllplus.com']


# Application definition

INSTALLED_APPS = (
    'account',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'social.apps.django_app.default',
    'images',
    'sorl.thumbnail',
    'actions',
    'django.contrib.sites',
    #'django_comments',
    'haystack',
    'taggit',
    #'django-private_chat',


    'django_messages',
    'whoosh',



)

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',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'stylplus.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 = 'stylplus.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'styleplus',
        'USER': 'styleplus',
        'PASSWORD': 'styleplus',
        'HOST': 'localhost',
        'PORT': '',
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/


STATIC_URL = '/static/'
STATIC_ROOT = '/home/kingiyk/stylplus/static/'




from django.core.urlresolvers import reverse_lazy

LOGIN_REDIRECT_URL = reverse_lazy('dashboard')
LOGIN_URL = reverse_lazy('login')
LOGOUT_URL = reverse_lazy('logout')

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'



ABSOLUTE_URL_OVERRIDES = {
    'auth.user': lambda u: reverse_lazy('user_detail', args=[u.username])
    }

SITE_ID = 1

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
        'URL': 'http://127.0.0.1:8983/solr/account'
    },
 }

#redis_host = os.environ.get('REDIS_HOST', 'localhost')

#CHANNEL_LAYERS = {
#    "default" : {
#        "BACKEND": "asgi_redis.RedisChannelLayer",
#        "CONFIG" : {
#            "hosts" : [(redis_host, 6379)],
 #           },
 #       "Routing": "multichat.routing.channel_routing",
  #      },
  #  }


# HAYSTACK_CONNECTIONS = {
# 'default': {
# 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
# 'PATH': WHOOSH_INDEX
# },
# }

DJANGO_MESSAGES_NOTIFY = False


# WHOOSH_INDEX = os.path.join[PROJECT_DIRECTORY, 'whoosh/']

and here is my html upload page which is supposed to display the image

{% extends "base.html" %}

{% load staticfiles %}


{% block title %}{{ user.username }}{% endblock %}
{% block content %}
    {% load thumbnail %}
    <div id="lonely">
     {% thumbnail image.user.profile.photo "40" as in %}
        <a href="{{ image.user.get_absolute_url }}">
            <img src="{{ in.url }}" class="gametime"></a>
            {% endthumbnail %}
    <a href="{{ image.user.get_absolute_url }}" class="time">{{ image.user.username }}</a>
   </div>

    <div id="details">
    {% thumbnail image.image "551" as im %}

        <a href="{{ image.image.url }}">
            <img src="{{ im.url }}" alt="{{ image.title }}"class="image-detail">
        </a>

    {% endthumbnail %}

    {% with total_likes=image.users_like.count users_like=image.users_like.all %}
        <div class="image-info">
         <div>
            <span class="count">
                <span class="total">{{ total_likes }}</span>
                like{{ total_likes|pluralize }}
            </span>
            {% with comments.count as total_comments %}

    {{ total_comments }} comment{{ total_comments|pluralize }}

{% endwith %}
<div id="float">
             <a href="#" data-id="{{ image.id }}" data-action="{% if request.user in users_like %}un{% endif %}like" class="like button">
                {% if request.user not in users_like %}
                 Like
                {% else %}
                 Unlike
                {% endif %}
             </a>
</div>

        </div>
        {{ image.title|linebreaks }}
    </div>

    <div id="my-chart"></div>
    <div class="image-likes">
        Liked by
        {% for user in image.users_like.all %}
            <div>
                {% thumbnail user.profile.photo "30" as in %}
                <img src="{{ in.url }}" class="gametime">
                {% endthumbnail %}
                <a href="{{ user.get_absolute_url }}">{{ user.username }}

            </div>
        {% empty %}

        {% endfor %}
    </div>
    {% endwith %}




{% for comment in comments %}
<div class="image-info">
    <p class="info">


        <a href="{{ comment.user.get_absolute_url }}" class="mine">{{ comment.user }}</a> {{ comment.comment }}


    </p>

</div>
{% empty %}

{% endfor %}

{% if new_comment %}
<p>Posted</p>
{% else %}
<div id="comments">
<form action="." method="post">
    {{ comment_form.as_p }}
    {% csrf_token %}
    <p><input type="submit" value="post"></p>
</form>
</div>
{% endif %}
</div>


I can’t see what the bug is. I’d appreciate your time

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

must be the permission settings on your server… change the media folder’s permission to read and write…

add this to you settings.py

MEDIAROOT = ’/home/kingiyk/stylplus/media/’
MEDIA
URL = ’/media/’

and add this to your main urls.py

from django.conf import settings
from django.conf.urls.static import static

below the urlpaterns add this

if settings.DEBUG:
urlpatterns += static(settings.STATICURL, documentroot=settings.STATICROOT)
urlpatterns += static(settings.MEDIA
URL, documentroot=settings.MEDIAROOT)

Submit an Answer