作者:Liushan2502897753 | 来源:互联网 | 2023-07-05 11:23
IamusingDjango1.5.4andIhaveaprojectwiththefollowingstructure:我使用的是Django1.5.4,我有一个项目的
I am using Django 1.5.4 and I have a project with the following structure:
我使用的是Django 1.5.4,我有一个项目的结构如下:
django_site
-django_site
-books # the app
-media
-images
-books
-authors
-static
-images
-templates
This is the necessary code:
这是必要的守则:
# settings.py
MEDIA_ROOT = '/root/django_site/books/media/'
MEDIA_URL = '/media/'
# models.py
class Book(models.Model):
image = models.ImageField(upload_to="images/books/")
# urls.py
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^books/$', 'books.views.get_all_books'),
)
My problem is that, after adding the image via the admin site, if I click on the image link below the upload button a 404
page shows up, complaining the path does not exist.
我的问题是,在通过admin站点添加图像之后,如果我点击上传按钮下面的图像链接,会出现一个404页面,抱怨这条路径不存在。
The request URL is http://127.0.0.1:8000/media/books/media/images/book/out_of_control_1.JPG
but in fact I want the result to be /root/django_site/books/media/images/out_of_control_1.JPG
.
请求URL为http://127.0.1:8000 /media/books/media/image /book/out_of_control_1。但实际上我希望结果是/root/django_site/books/media/images/out_of_control_1.JPG。
How do I fix that? Looking forward to your responses.
我该怎么做呢?期待您的回复。
1 个解决方案