Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Last active April 23, 2016 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivabudh/97fcdf962e18700050d32febbafcd22a to your computer and use it in GitHub Desktop.
Save sivabudh/97fcdf962e18700050d32febbafcd22a to your computer and use it in GitHub Desktop.
Uploading file example
def upload_file(request):
if request.method == 'POST':
form = NetworkScriptForm(request.POST, request.FILES)
if form.is_valid():
content = request.FILES['file'].read()
networkscript = NetworkScript.objects.create(
title=request.POST['title'],
script=content,
)
return render(request, 'bod_detail.html', {'networkscript': networkscript})
else:
form = NetworkScriptForm()
return render(request, 'networkscripts_upload.html', {'form': form})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment