CHO PHÁT TRIỂN CHỈ
Bạn có thể thiết lập một máy chủ phương tiện truyền thông tĩnh để sử dụng với máy chủ phát triển của họ bằng cách làm này trong tệp urls.py
của bạn. Tôi có kèm theo mã cho thấy làm thế nào tôi sử dụng nó (cùng với các điều kiện DEBUG buộc.)
from django.conf import settings
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^$', 'views.index'),
# Accounts
(r'^accounts/login/$', 'views.user_login'),
(r'^accounts/logout/$', 'views.user_logout'),
# Contrib Modules
(r'^admin/(.*)', admin.site.root),
)
if settings.DEBUG :
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
)
tôi đặt tôi MEDIA_ROOT
trong một thư mục con của html/phương tiện truyền thông và liên kết với nó như vậy trong settings.py
MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'html/media/').replace('\\','/')
Sau khi phát triển xong, dự án sẽ được triển khai tới máy chủ web nơi các tệp phương tiện tĩnh sau đó được phân phát theo Apache sử dụng chỉ thị.
Nguồn
2008-12-31 21:51:00
+1: liên kết tới tài liệu. –