Reputation: 3762
I'm tyring to override the url to call specific methods for different types of urls. Code below
Resources.py
class LCUserResource(ModelResource):
class Meta:
queryset = LCUser.objects.all()
resource_name= 'lcuser'
authorization = Authorization()
def override_urls(self):
return [
url(r'^register/'%
(self._meta.resource_name, trailing_slash()), self.wrap_view('register_user'), name="api_register_user"),
]
urls.py
v1_api = Api(api_name='v1')
v1_api.register(LCUserResource())
urlpatterns = [
url(r'^api/', include(v1_api.urls)),
]
I'm trying to access the api via http://localhost:8000/api/v1/lcuser/register/
But i'm getting the error global name urls is not defined.
I tried importing from django.conf.urls.defaults import *
Then I get No module named defaults
Upvotes: 2
Views: 5178
Reputation: 174624
The django.conf.urls.default
was removed in django 1.6 as stated in the depreciation notes:
django.conf.urls.defaults will be removed. The functions include(), patterns() and url() plus handler404, handler500, are now available through django.conf.urls.
So, it seems like the documentation for tastypie
hasn't been updated for django 1.8; you can fix the import error by fixing your import as mentioned in the release note:
from django.conf.urls import url
This will solve one issue - your next problem is here:
r'^register/'% (self._meta.resource_name, trailing_slash())
Not sure you what you are trying to do here as you are parsing a string (with %
) but there are no variables to substitute. It is the same problem as this:
>>> a = 'world'
>>> 'hello' % (a,)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
You probably want the following:
r"^register/(?P<resource_name>%s)%s$" % (self._meta.resource_name, trailing_slash())
Upvotes: 2