How doesn't it work?

1. Does the uploaded file appear where you expect it to?
2. If you construct the URL properly in your browser, can you access
it directly?
3. What is the URL being output in your templates?


On Tue, Apr 14, 2015 at 9:44 AM, dk <demi...@gmail.com> wrote:
> maybe I need to simplify my question.
>
>
> how do I use media_url  in windows?
>
>
>
>
>
>
> On Wednesday, April 8, 2015 at 10:56:27 AM UTC-5, dk wrote:
>>
>> 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.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c4053a51-ec3b-4445-8706-821ee2d539e1%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD4ANxW-FETEmsF%3DvtxJ%2BZ0j5UDwZhqaUyPMUNXivShiyTPJ0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to