I have a problem with displaying the uploaded image from the admin panel, which does not appear on the site. The following error that the server returns:
我在管理面板上显示上传的图片时出现问题,该图片未显示在网站上。服务器返回以下错误:
Internal Server Error: /media/images/c5.png
Traceback (most recent call last):
File "/Users/marcingrzywacz/Desktop/polano2/cms/lib/python2.7/site-packages/django/core/handlers/base.py", line 92, in get_response
response = middleware_method(request)
File "/Users/marcingrzywacz/Desktop/polano2/cms/lib/python2.7/site-packages/django/middleware/common.py", line 69, in process_request
if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "/Users/marcingrzywacz/Desktop/polano2/cms/lib/python2.7/site-packages/django/core/urlresolvers.py", line 551, in is_valid_path
resolve(path, urlconf)
File "/Users/marcingrzywacz/Desktop/polano2/cms/lib/python2.7/site-packages/django/core/urlresolvers.py", line 440, in resolve
return get_resolver(urlconf).resolve(path)
File "/Users/marcingrzywacz/Desktop/polano2/cms/lib/python2.7/site-packages/django/core/urlresolvers.py", line 321, in resolve
sub_match = pattern.resolve(new_path)
File "/Users/marcingrzywacz/Desktop/polano2/cms/lib/python2.7/site-packages/django/core/urlresolvers.py", line 223, in resolve
return ResolverMatch(self.callback, args, kwargs, self.name)
File "/Users/marcingrzywacz/Desktop/polano2/cms/lib/python2.7/site-packages/django/core/urlresolvers.py", line 230, in callback
self._callback = get_callable(self._callback_str)
File "/Users/marcingrzywacz/Desktop/polano2/cms/lib/python2.7/site-packages/django/utils/functional.py", line 31, in wrapper
result = func(*args)
File "/Users/marcingrzywacz/Desktop/polano2/cms/lib/python2.7/site-packages/django/core/urlresolvers.py", line 104, in get_callable
(lookup_view, mod_name))
ViewDoesNotExist: Could not import django.views,static.serve. Parent module django.views,static does not exist.
I would add that it was only following inclusion in the file urls.py
我想补充一点,它只是包含在文件urls.py中
if settings.DEBUG :
urlpatterns + = patterns ('',
( r ' ^ media / ( ? P < path> . *) $ ', ' django.views , static.serve ', {' document_root ' : settings.MEDIA_ROOT } )
)
I view the page correctly , but no picture. My page is on the local server
我正确查看页面,但没有图片。我的页面在本地服务器上
Can anyone help. Thank you in advance.
谁能帮忙。先谢谢你。
the urls.py file:
urls.py文件:
from django.conf.urls import patterns, include, url
from django.conf import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^article/',include('articles.urls')),
# Examples:
# url(r'^$', 'projekt.views.home', name='home'),
# url(r'^projekt/', include('projekt.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
#url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views,static.serve', {'document_root': settings.MEDIA_ROOT}),
)
settings.py file:
settings.py文件:
MEDIA_ROOT = '/Users/marcingrzywacz/Desktop/polano2/cms/projekt/media/' #pelna sciezka musi byc na localu
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = '/media/'
And the last I add on site:
最后我在网站上添加:
<img alt="" src="{{ article.image.url }}">
1 个解决方案
#1
1
Thank You Evert for pointing me to the error. Should be 'django.views.static.serve',
instead 'django.views,static.serve',
谢谢Evert指出我的错误。应该是'django.views.static.serve',而不是'django.views,static.serve',
#1
1
Thank You Evert for pointing me to the error. Should be 'django.views.static.serve',
instead 'django.views,static.serve',
谢谢Evert指出我的错误。应该是'django.views.static.serve',而不是'django.views,static.serve',