擅长:python、mysql、java
<p>我在你的帮助下仔细看了一下,发现了一些东西:)</p>
<p>所以基本上我要做的是:</p>
<pre><code>from django.core.files.storage import FileSystemStorage
fss = FileSystemStorage()
filepath = fss.get_available_name(filepath)
</code></pre>
<p>谢谢大家:)</p>
<p>附言:如果你感兴趣,来自<a href="https://github.com/django/django/blob/1.5.5/django/core/files/storage.py#L184" rel="nofollow">django.core.file.storage.FileSystemStorage._save</a>的评论说:</p>
<blockquote>
<p>There's a potential race condition between get_available_name and
saving the file; it's possible that two threads might return the
same name, at which point all sorts of fun happens. So we need to
try to create the file, but if it already exists we have to go back
to get_available_name() and try again.</p>
</blockquote>