in my settings
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = "/media/"
my view to accept files.
def request_page(request):
#todo since sqlite my get stuck between 2 submittion at the same time,
# submit, if it cant try again and then message that ask the user to try in 5 mins.
try:
if request.method == "POST":
form = Submit_Form(request.POST, request.FILES)
if form.is_valid():
email = form.cleaned_data["email"]
file = request.FILES["file"]
# we make the message true or false so we can display color in the html template.
if file.name.endswith(".ini"):
per = Person(email=email, date_submitted=datetime.datetime.now(), file=file)
per.save()
message = ["Thanks, we receive your file: " + email, "True"]
forma = Submit_Form()
else:
message = ["its not the appropriate type of file, please verify.", "False"]
forma = Submit_Form()
and this is how I am making my model
def content_file_name(instance, filename):
here is where I think is the problem, windows like \ and Linux / but even using os.path.join I wasn't able to make it work,
I also try hard code the path using \\.join instead if
os.name == "nt":
# path = "\\".join(["submitted_ini_files", filename + "___" + str(instance.email) + "___" + str(datetime.datetime.now())])
path = os.path.join("submitted_ini_files", filename + "___" + str(instance.email) + "___" + str(datetime.datetime.now())) print path
print MEDIA_URL
# path = os.path.join("submitted_ini_files", filename + "___" + str(instance.email) + "___" + str(datetime.datetime.now() ))
return path
else:
print "other than nt"
return "/".join(["submitted_ini_files", filename + "___" + str(instance.email) + "___" + str(datetime.datetime.now())])
class Person(models.Model):
email = models.EmailField(blank=True, null=True)
file = models.FileField(blank=True, null=True, upload_to=content_file_name)
date_submitted = models.DateTimeField(blank=True, null=True)
any tips on how to make this work? thanks.