I'm using the django-contrib package django-profiles, and everything is working great - my only issue is that I would like the form to upload a file (for an avatar), unfortunately - the form does not upload the file.
Has anyone successfully managed to get file uploads working with django-profiles? I want to avoid having to set up a seperate upload view just for the avatar?
Any help is much appreciated!
Thanks,
Martin
In your template add enctype="multipart/form-data" in form tag. Example:
<form method="post" action="." enctype="multipart/form-data">
Related
I am fairly new to the Django and HTML world and and would like to be able to select a video file and then play it in an edited version (AI classification and some OpenCV editing).
At the moment, playing of a local file works in that way that the file path of my dummy video file is fixed in my script where I load the VideoStream.
However, I would like to be able to specify via HTML input which file to load.
I have the problem that I do not know how to pass the selected file.
Via urls, parameters can be passed, but I do not know how I can pass the path or URL of the video file as a parameter. Or can something like this be achieved via post requests and if so how?
Here are parts of my script (I don't use post request for this at the moment):
<form action="" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<input id="myFileInput" type="text">
<input class="button1" id="inputfield" name="upload" type="file" accept="video/*" onchange="document.getElementById('myFileInput').src = window.URL.createObjectURL(this.files[0]); document.getElementById('buttonStart').className = 'button'; this.form.submit()" value="Select a File"/>
</form>
The file path is stored in 'myFileInput'. But I could also get the file path through post request. Then I have the problem, that no class instance that I know where I could save that path and load it later.
<img id="demo" src="">
and the function for
function video_on() {
document.getElementById("demo").src = "{% url 'mask_feed' urlpath='path_I_would_like_to_pass' %}"; //
document.getElementById("wait").innerHTML = "Turning on. . . . .";
setTimeout(showText, 3000);
}
and the urls.py file:
path('mask_feed/<path:urlpath>', views.mask_feed, name='mask_feed'),
And of course I have a mask_feed method in my views.py that takes urlpath as argument.
How can I "insert" the file path I get with html insert into the Django template "{% url 'mask_feed' urlpath='path_I_would_like_to_pass' %}"?
I would like to do something like this:
document.getElementById("demo").src = "{% url 'mask_feed' urlpath='document.getElementById('myFileInput').src' %}"
But it doesn't work because of the quotation marks.
And if this is not the way to go, how should I do it?
I am trying to get my site url like; https://www.example.com/ in admin twig file for my custom module.
Can anyone help me please?
I tried this, but no result;
{{ HTTPS_CATALOG }}
In your corresponding controller file define:
$data['site_url'] = $_SERVER['HTTP_HOST'];
in corresponding twig file you can call this data:
{{ site_url }}
If the answer are useful for you, can you mark it "This answer is useful"
I was following LPTHW ex51 by Zed shaw http://learnpythonthehardway.org/book/ex51.html, and was doing his study drills on web.py , i am a web.py beginner and was successful in uploading an image on Webpage form and then storing it in a local folder. The issue is each image I store , replaces the earlier one. Also I cant figure out how to upload multiple images on server and store them all.
Here is my class Upload in app.py:
class Upload(object):
def GET(self):
web.header("Content-Type","text/html; charset=utf-8")
return render.upload()
def POST(self):
x= web.input(myfile={})
filedir= "C:/Users/tejas/Documents/filesave"
if 'myfile' in x:
fout = open(filedir + '/' + 'myfile.jpg', 'wb') # creates the file where the uploaded file should be stored
fout.write(x.myfile.file.read()) # writes the uploaded file to the newly created file.
fout.close() # closes the file, upload complete
return "Success! Your image has been saved in the given folder."
raise web.seeother('/upload')
and my upload form- upload.html :
<html>
<head><title>
<div id="header" <h1 style="color:blue;">Upload image file</h1><div/>
</title></head>
<body background-color=light-blue,font-family=verdana,font-size=100%;>
<form method="POST" enctype="multipart/form-data" action="">
<input type="file" name="myfile"/>
<br/> <br/><br/>
<input type="submit"/>
</form>
</body>
</html>
I tried searching a lot for similar questions but all in PHP , and so I try something similar with the code but I could not get it working. Any suggestions to improve the code?
the reason your code is replacing the earlier on is because your hardcoding the path to save the image
fout = open(filedir + '/' + 'myfile.jpg', 'wb')
everytime you upload the file to be altered is the same this could be corrected by adding an new name each time your uploading new file or extracting the name from web input
fout = open(filedir + '/' + x.myfile.filename, 'wb');
according to python when opening for writing files with the same name will be erased
make sure each new file you upload has different name from the previous uploaded
I'm working on a widget with some backend settings. One of the settings would allow clients to provide their own CSS files to customize the look of the widget. I put a link to a base CSS file, they download it, make their changes and reupload it to create their own custom theme.
The problem is when I try to upload the file, it uploads but turns it into gibberish. Example:
–wTSهϽ7½Ð" %ôz Ò;HQ‰I€P†„&vDF)VdTÀG‡"cEƒ‚b× òPÆÁQDEåÝŒk ï5óÞšýÇYßÙç·×Ùgï}׺�Pü‚ÂtX€4¡XîëÁ\ ËÄ÷XÀáffGøDÔü½=™™¨HƳöî.€d»Û,¿P&sÖÿ‘"7C$�EÕ6<~&å”S³Å2ÿÊô•)2†12¡ ¢¬"ãįlö§æ+»É˜—&ä¡Yμ4žŒ»PÞš%ᣌ¡\˜%àg£|e½TIš�å÷(ÓÓøœL�0™_Ìç&¡l‰2Eî‰ò�”Ä9¼r‹ù9hž�x¦g䊉Ib¦×˜iåèÈfúñ³Sùb1+”ÃMáˆxLÏô´Ž0€¯o–E%Ym™h‘í
Here is my upload code:
<cffile
action="UPLOAD"
filefield="form.vchrThemeFile"
destination="C:\path\to\directory\"
accept="text/css"
nameconflict="makeunique">
I am using enctype="multipart/form-data" on the form.
<form action="<cfoutput>#submit#</cfoutput>" method="post" enctype="multipart/form-data">
Thank you
I have trying since a few days to change the enctype in joomla registration page. I am not a pro at Joomla. I edited
components/com_users/views/registration/tmpl/default.php
and added the enctype attribute to the form line as, so now it looks like this:
<form id="member-registration" enctype="multipart/form-data" action="<?php echo
JRoute::_('index.php?option=com_users&task=registration.register'); ?>"
method="post" class="form-validate" >
However, the change is not being reflected on the user side :(.
I want to change the enctype to multipart/form-data to allow image uploads via Profile Picture plugin. I tried using K2 registration form as well, but with no success. Any help is highly appreciated.
Your template probably has an override for the output. Have a look at the file in /templates/yourtemplate/com_users/registration/default.php
Some doc about template overrides can be found here: http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core