python - Problems with media and migrations -
have problems. 1)in production django tries access photos @ http://"ip_address"/images/"image".jpg url images must in http://"ip_address"/media/images/"image".jpg 2)i have added 2 more fields (alt , text) existing model. migrations work , show fields added can not see them in admin panel ( have added them list_display) , can not access them in templates.
settings media media_root = os.path.join(base_dir, 'media') media_url = 'http://"ip_address"/media/' urls django.conf.urls import patterns, include, url django.conf.urls.static import static django.contrib import admin django.contrib.staticfiles.urls import staticfiles_urlpatterns 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 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 django.contrib import admin main.models import slider class slideradmin(admin.modeladmin): list_display = ('image','alt','caption','text') admin.site.register(slider,slideradmin)
see https://docs.djangoproject.com/en/1.8/howto/static-files/
add static_url settings.py
Comments
Post a Comment