Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:16:27+00:00 2026-06-18T12:16:27+00:00

I have created a custom handler ( CustomHandler ) that isn’t tied to a

  • 0

I have created a custom handler (CustomHandler) that isn’t tied to a model in the ORM and I think it’s rigged up correctly, but I’m getting an ImportError: cannot import CustomHandler when trying to import it into my resources.py. Here is my setup:

custom_handlers.py:

from piston.handler import BaseHandler

class CustomHandler(BaseHandler):
    allowed_methods = ('GET',)

    def read(self, request):
        return 'test'

resources.py:

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)

urls.py:

from django.conf.urls.defaults import patterns, url

from api.resources import custom_handler

urlpatterns = patterns('',
    url(r'^things/$', custom_handler),
)

UPDATE: I’ve tried manually compiling the pys into pycs with no luck. I also read this in Piston’s docs:

When you create a handler which is tied to a model, Piston will
automatically register it (via a metaclass.)

But I can’t find anything in the docs about creating a handler that isn’t tied to a model, specifically how to register it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:16:28+00:00Added an answer on June 18, 2026 at 12:16 pm

    Had to add from api.handlers.custom_handlers import CustomHandler to api/handlers/__init__.py

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom event in flex 3.5. But the handler is not
I have created a custom method that will return unique items, together with the
I have created a custom control but I can't bind a property to the
I have an unmanaged c++ application that provides a custom _matherr handler. When this
I have created a custom even class which is pretty basic. But when calling
I have created custom posts and I want one page in my site to
I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in
I have created custom cell in which there are n number of image views.
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have created a custom post type named People. I have created a page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.