I develop an application in C++ with WWW interface in Django.
So far I have working framework in C++ with Boost.Python wrapper compiled to shared object in Linux.
Now I try to run this framework in Django. When I pass string from form “CharField” I get this error:
Python argument types in
CoreSystem.setOutput(CoreSystem, unicode)
did not match C++ signature:
setOutput(CoreSystem {lvalue}, std::string)
Code responsible for that is here:
form = AnalyzeForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
s.setOutput(cd["output"])
where s is this CoreSystem object. If I type it like this:
s.setOutput("DatabaseOutput")
it works fine. I used also str(cd[“output”]) but after that nothing happens.
I’m using Django 1.4.1 and Python 2.7.3
You can use the
encodemethod to convert a Unicode string to a byte string before sending it off to the C++ code that expects a string:The
UTF-8encoding is a reasonable default for Unicode strings. Ifcd["output"]is already an ASCII string, encoding will not change it; if it contains binary data, you will get an exception.