MEDIA_URL doesnt work in windows but works on linux

35 views
Skip to first unread message

dk

unread,
Apr 8, 2015, 11:56:27 AM4/8/15
to django...@googlegroups.com
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. 

dk

unread,
Apr 14, 2015, 10:44:50 AM4/14/15
to django...@googlegroups.com
maybe I need to simplify my question.


how do I use media_url  in windows?

Stephen J. Butler

unread,
Apr 14, 2015, 12:14:56 PM4/14/15
to django...@googlegroups.com
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?
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@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.
Reply all
Reply to author
Forward
0 new messages