0

In Django we have a model field called TextField. and A simple html page which have a tag <textarea id="textarea" cols="10" rows="5" wrap="off"></textarea>

I write Python code in this area and press submit button so that it will be saved in DB. The problem is when I retrieve back from DB it looses its formatting. I will have to show end user as the same format as he entered.

as this can be seen here http://ideone.com/B5AUiQ. I'm not sure about how any other sites like codeacademy, spoj, topcoder, codechef, codepad etc uses this and what could be the best solution.

considering Django and in general both

I found these threads but not clearly shows how to do it in general

How to store formatted text in MySQL table?

How to safely insert code in mySQL database

How can I store PHP code inside of a mysql table

Community
  • 1
  • 1
rocktheparty
  • 217
  • 4
  • 10
  • 1
    This is probably more a case of how you are actually parsing the text to be stored in the db rather than the db itself... all a database would see is a `\t` or similar for tabs etc – Sayse Jan 05 '16 at 13:44
  • What do you mean with "formated" ? Is it HTML formatting ? Are you using a editor like tinymce for it ? – Dric512 Jan 05 '16 at 14:29
  • Look into javascript libraries for code highlighting. This way you can save and render plain text in your Django project and let the JS handle the rest. – allcaps Jan 05 '16 at 14:34

0 Answers0