Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
17284 Переглядів

I have created a hello world module following this tutorial https://www.odoo.com/documentation/9.0/howtos/website.html and it's working fine.

Now I would like to implement a file upload on this hello world page.

My templates.xml file is like this (I just get the relavant part):

<form action="/upload" method="post" enctype="multipart/form-data">    
Upload file: <input type="file" name="uploaded" /> <br />
<input type="submit" name="submit" value="Submit" />
</form>

My controllers.py is like this (I also just give the relevant part,  my module name is "sunxia") :

# -*- coding: utf-8 -*-
from openerp import http
import cgi
class Sunxia(http.Controller):  
@http.route('/upload', type="http", auth="public", methods=['GET', 'POST'])
def upload_file(self):
form_data = cgi.FieldStorage()
file_data = form_data['uploaded'].value
fp =open('/uploads','wb')
fp.write(file_data)
fp.close()
return 

But after choosing a file and click the upload button, the /uploads page gave an error messange:

TypeError: upload_file() got an unexpected keyword argument 'uploaded'

It seems that it cannot get the uploaded file in my controller. Can anyone told my how may I change my controller to implement this simple upload?

Since I'm quite new to odoo and python... I would strongly appreciate if you could give me more detail about this.

Аватар
Відмінити

You can take a look in module website_hr, the user can upload cv! (Without cgi)

Автор

Sorry? But I cannot find the upload in website_hr... Could you tell me where it is?

Найкраща відповідь

Have a look at this one...

https://www.odoo.com/forum/help-1/question/add-attachement-from-website-118903

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
черв. 25
1468
0
жовт. 24
970
0
серп. 24
1259
1
лип. 23
5634
1
лют. 23
4320