Note that there are some explanatory texts on larger screens.

plurals
  1. POImportError for Django Piston handler that isn't tied to a model
    primarykey
    data
    text
    <p>I have created a custom handler (<code>CustomHandler</code>) that isn't tied to a model in the ORM and I think it's rigged up correctly, but I'm getting an <strong><code>ImportError: cannot import CustomHandler</code></strong> when trying to import it into my <code>resources.py</code>. Here is my setup:</p> <p><strong>custom_handlers.py</strong>:</p> <pre><code>from piston.handler import BaseHandler class CustomHandler(BaseHandler): allowed_methods = ('GET',) def read(self, request): return 'test' </code></pre> <p><strong>resources.py</strong>:</p> <pre><code>from piston.resource import Resource from piston.utils import rc import simplejson as json from api.authentication import DjangoAuthentication from api.handlers import CustomHandler # ERROR THROWN HERE auth = DjangoAuthentication(realm='...') class JSONResource(Resource): def determine_emitter(self, request, *args, **kwargs): """ Default to the json emitter. """ try: return kwargs['emitter_format'] except KeyError: pass if 'format' in request.GET: return request.GET.get('format') return 'json' def form_validation_response(self, e): """ Turns the error object into a serializable construct. """ resp = rc.BAD_REQUEST json_errors = json.dumps( dict( (k, map(unicode, v)) for (k, v) in e.form.errors.iteritems() ) ) resp.write(json_errors) return resp custom_handler = JSONResource(CustomHandler, authentication=auth) </code></pre> <p><strong>urls.py</strong>:</p> <pre><code>from django.conf.urls.defaults import patterns, url from api.resources import custom_handler urlpatterns = patterns('', url(r'^things/$', custom_handler), ) </code></pre> <p><strong>UPDATE:</strong> I've tried manually compiling the <code>py</code>s into <code>pyc</code>s with no luck. I also read this in <a href="https://bitbucket.org/jespern/django-piston/wiki/FAQ#!why-does-piston-use-fields-from-previous-handlers" rel="nofollow">Piston's docs</a>:</p> <blockquote> <p>When you create a handler which is tied to a model, Piston will automatically register it (via a metaclass.)</p> </blockquote> <p>But I can't find anything in the docs about creating a handler that isn't tied to a model, specifically <em>how to register it</em>.</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.
    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