prismicio / python-django-starter

Starter project for Django – Works with any prismic.io repository
https://developers.prismic.io
8 stars 3 forks source link

How is the /preview endpoint used? #2

Open pconerly opened 9 years ago

pconerly commented 9 years ago

Hi,

I'm trying to figure out how to use this django project to preview a document. (I'm trying it in this project before integrating it into our actual site.)

I'm trying to preview this doc: http://lesbonneschoses-vbpnsiaaab4awxye.prismic.me/blog/VbqwmB0AAKsJc6S_/derp2

By trial and error I figured that the format is:

http://127.0.0.1:8000/preview?token=http://lesbonneschoses-vbpnsiaaab4awxye.prismic.me/blog/VbqwmB0AAKsJc6S_/derp2

Maybe include a comment about that in views.py?

I'm also still getting an error---

  File "/Users/peterconerly/.virtualenvs/prismic/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/Users/peterconerly/code/prismic-django-starter/prismic_app/views.py", line 60, in preview
    url = prismic.api.preview_session(token, prismic.link_resolver, '/')
  File "/Users/peterconerly/.virtualenvs/prismic/lib/python2.7/site-packages/prismic/api.py", line 88, in preview_session
    main_document_id = get_json(token, request_handler=self.request_handler).get("mainDocument")
  File "/Users/peterconerly/.virtualenvs/prismic/lib/python2.7/site-packages/prismic/connection.py", line 64, in get_json
    raise HTTPError(status_code, str(text_result))
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 360: ordinal not in range(128)

Thoughts?

pconerly commented 9 years ago

I have a local instance up on ngrok, and I've configured it with my repo, and I'm getting a different error:

http://peterlocal.ngrok.com/preview?token=https%3A%2F%2Flesbonneschoses-vbpnsiaaab4awxye.prismic.io%2Fpreviews%2FMEueWFdK6aBBlZ8r

erwan commented 9 years ago

Hi,

The preview endpoint is called by prismic.io when you click the "preview" button in the writing room.

A token is generated that will enable the kit to retrieve the content corresponding to the document, even if it's a draft.