Note that there are some explanatory texts on larger screens.

plurals
  1. PObuild an API service in Django
    primarykey
    data
    text
    <p>I want to build an API service using Django. A basic workflow goes like this:</p> <p>First, an http request goes to <code>http://mycompany.com/create?id=001&amp;callback=http://callback.com</code>. It will create a folder on the server with name 001.</p> <p>Second, if the folder does not exist, it will be created. You get response immediately in XML format. It will look like:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;response&gt; &lt;status&gt; &lt;statusCode&gt;0&lt;/statusCode&gt; &lt;message&gt;Success&lt;/message&gt; &lt;/status&gt; &lt;group id="001"/&gt; &lt;/response&gt; </code></pre> <p>Finally, the server will do its job (i.e. creating the folder). After it is done, the server does a callback to the URL provided.</p> <p>Currently, I use </p> <pre><code>return render_to_response('create.xml', {'statusCode': statusCode, 'statusMessage': statusMessage, 'groupId': groupId, }, mimetype = 'text/xml') </code></pre> <p>to send the XML response back. I have an XML template which has <code>statusCode</code>, <code>statusMessage</code>, <code>groupId</code> placeholders.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;response&gt; &lt;status&gt; &lt;statusCode&gt;{{ statusCode }}&lt;/statusCode&gt; &lt;message&gt;{{ statusMessage }}&lt;/message&gt; &lt;/status&gt; {% if not statusCode %} &lt;group id="{{ groupId }}"/&gt; {% endif %} &lt;/response&gt; </code></pre> <p>But in this way I have to put step 3 before step 2, because otherwise step 3 will not be executed if it is after <code>return</code> statement. </p> <p>Can somebody give me some suggestions how to do this? Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload