-1

have problems. 1)In production Django tries to access photos at http://"ip_address"/images/"image".jpg URL however images must be in http://"ip_address"/media/images/"image".jpg 2)I have added two more fields (alt and text) to existing model. Migrations work and show that the fields are added but i can not see them in the admin panel ( I have added them to the list_display) and i can not access them in my templates.

   settings for media
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = 'http://"ip_address"/media/'

urls
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf import settings
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^media/(?P<path>.*)$', 'django.views.static.serve',

    url(r'^$','main.views.mainpage'),


)+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += staticfiles_urlpatterns()

models
from django.db import models

class Slider(models.Model):
        image = models.ImageField(upload_to = 'images/')
        caption = models.TextField()
        alt = models.CharField(max_length = 20, default = "an image")
        text = models.CharField(max_length = 5, null=True)
admin
from django.contrib import admin
from main.models import Slider

class SliderAdmin(admin.ModelAdmin):
    list_display = ('image','alt','caption','text')

admin.site.register(Slider,SliderAdmin)
mightycoder
  • 71
  • 3
  • 12
  • Please ask one question per question, since the two question you ask here are unrelated (even if in the same Django project). –  Jun 01 '15 at 07:37
  • You might want to remove the `static` helper function from your `urlpatterns`; that's for `DEBUG` mode only, not for production mode. –  Jun 01 '15 at 07:38
  • Thanks @Evert i did not know about it – mightycoder Jun 01 '15 at 08:47

1 Answers1

0

See https://docs.djangoproject.com/en/1.8/howto/static-files/

Add a STATIC_URL to your settings.py

fiacre
  • 1,150
  • 2
  • 9
  • 26