1

I'm switching my web site to Django from another content management system and I'm having trouble importing the HTML to Django using fixtures, specifically with "Events", which is a model in my Django app. The model is as follows:

class Event(models.Model):
    event_name = models.CharField(max_length=100)
    event_date = models.DateTimeField()
    event_city = models.CharField(max_length=100)
    event_province = models.CharField(max_length=100)
    event_location = models.CharField(max_length=100, blank=True)
    event_details = models.TextField(blank=True)

event_details is HTML containing the details for the specified event. When importing the data using syncdb I receive a DeserializationError: Problem installing fixture 'events.json': Invalid control character at: line 274 column 73 (char 7090)

Here is an example of the json that I'm trying to import:

{
  "model": "events.Event",
  "pk": 26,
  "fields": {
  "event_name": "Random Event",
  "event_date": "2008-09-06 00:00:00+00:00",
  "event_city": "Toronto",
  "event_province": "ON",
  "additional_info": { "data": "Promoter: Random Person Productions<BR>
Contact: John Doe: (555) 555-7777<BR>
Promoter Website: <A HREF="http://www.foo.com">www.foo.com</A>" }
  }
},

The error occurs after the first BR on the first line of the "additional_info". What am I doing wrong?

Regards.

Nse
  • 305
  • 4
  • 21
  • 1
    Please note that django is **not** a content management system (you have django-cms for that) – yuvi Feb 03 '14 at 09:09

1 Answers1

1

Possibly two things:

  1. Those double quotes in the <A> tag. Double quotes are the string delimiter in JSON, so when they’re included in a JSON string they should be escaped with a backslash, like this:

    { "data": "Promoter: Random Person Productions<BR>
    Contact: John Doe: (555) 555-7777<BR>
    Promoter Website: <A HREF=\"http://www.foo.com\">www.foo.com</A>" }
    
  2. Newline characters in the HTML. JSON strings also can’t contain newline characters, so if they’re actually in your JSON (rather than being something you put in for readability when entering the code on Stack Overflow) and you want them to stay there, you’ll need to escape them too:

    { "data": "Promoter: Random Person Productions<BR>\\nContact: John Doe: (555) 555-7777<BR>\\nPromoter Website: <A HREF=\"http://www.foo.com\">www.foo.com</A>" }
    
Community
  • 1
  • 1
Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270