I have heard that static file configuration for Django is troublesome. The key is that there is no good tutorial to talk about this. Even if there is a tutorial, it is also vague and I have been exploring for 2 days, finally, the problem of uploading and downloading via filefield in Admin is fixed. The record is as follows:
1. Modify settings. py.
# Physical root directory of the uploaded file
Media_root = 'd:/output/Django/landsupervisor/media'
# The uploaded file depends on this URL prefix to obtain the file. This prefix will eventually be mapped to the preceding media_root (in the URL. in Py), This prefix must be separated from admin_media_prefix below. I set the two to the same, so I always prompt that the uploaded file cannot be found.
Media_url = '/mymedia /'
# Admin's own static directory URL prefix. All static files in Admin are obtained through this prefix. The system will map it to a file similar to X: \ Django-1.2.1 \ Django \ contrib \ admin \ Media Directory
Admin_media_prefix = '/Media /'
2. Modify URL. py
Append this sentence to the urlpatterns variable (R' ^ mymedia /(? P <path>. *) $ ', 'django. Views. Static. serv', {'document _ root': settings. media_root }),
It is to map the media_url prefix set on the server to the physical path settings. media_root through the Django static service.
3. the admin model can be used.
XFile = filefield (upload_to = 'images ')
Admin automatically has a form control to upload files.