hi there, my application are almost frontend, what I meant by that, similar to json formatter, codePen, jsFiddle and some online graphers. to be more focused, I have specific views, let's say, a markdown editor, that you can type from left, and outlook appearance render to right.
here, it's a bit intricate. For some user cases: in a form, that the user can input raw text into a textarea, and it's markdown supported, therefore, I need to write a button, see in editor, which takes all user's current input text, and open a new tab with the markdown editor. The difficulty of this, is that those raw text do not need to be saved, the user only need to see the rendered effect, but django only works with model.
I thought of many ways:
but I failed to make it work.
template
<!-- some code above -->
{% comment %} form.content returns a string {% endcomment %}
{{ form.content }}
<button>see in editor</button>
<!-- some code below -->
javascript
const content = document.querySelector('#id_content');
const button = document.querySelector('button');
button.onclick = () => {
$.ajax({
type: "POST",
url: "{% url 'some-view-name' %}",
data: {
content: content.value,
},
success: function(url){
// return the link of markdown editor
window.open(url);
},
error: function(res){
console.log(res);
},
})
}
this javascript is just an attempt, which I have no idea how to write the view.
if I got you confused, I am sorry, please look at: Web: how to redirect to a CodePen or JsFiddle with information filled?, this kind is exactly what I am trying to do, an api backend.
I have been working on the issue for a week, frustrated, I will be very grateful for any of the help you may offer: