How to convert in Django unicode to C++ std::string

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

where s is this CoreSystem object. If I type it like this:


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 encode method to convert a Unicode string to a byte string before sending it off to the C++ code that expects a string:


The UTF-8 encoding is a reasonable default for Unicode strings. If cd["output"] is already an ASCII string, encoding will not change it; if it contains binary data, you will get an exception.

Need Your Help

Is it possible to use OutputCache on mvc JsonResult controller methods? json outputcache

I am trying to do this, and it leads to result with contentlen 0

@Html tags are not displayed in a div? html.actionlink

I'm working on asp.Net MVC4 project, and I need to create ActionLink for each element of a list.