Monday, September 25, 2017

POST method on localhost

I've created a simple form for data upload.  I'm testing it through localhost and was wondering if this is realistic.  Web development is a new area for me so bare with me please if this is a laughable question.  I uploaded a 1GB file and it was uploaded and moved to a folder in my project in a matter of a few seconds.

def simple_upload(request):
   
if request.method =='POST' and request.FILES['myfile']:
        myfile
= request.FILES['myfile']
        fs
= FileSystemStorage()
        filename
= fs.save(myfile.name, myfile)
        uploaded_file_url
= fs.url(filename)
       
return render(request, 'simple_upload.html', {
           
'uploaded_file_url': uploaded_file_url
   
})

   
return render(request, 'simple_upload.html')

{% load static %}

{% block content %}
 
<form method="post" enctype="multipart/form-data">
   
{% csrf_token %}
   
<input type="file" name="myfile">
   
<button type="submit">Upload</button>
  </
form>

 
{% if uploaded_file_url %}
   
<p>File uploaded at: <a href="{{ uploaded_file_url }}">{{ uploaded_file_url }}</a></p>
 
{% endif %}

 
<p><a href="{% url 'dashboard' %}">Return to home</a></p>
{% endblock %}

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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bf2476d2-8470-4c91-8590-99ecc4f477de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment