concentricsky / django-tastypie-swagger

An adapter to use swagger-ui with django-tastypie.
Other
132 stars 144 forks source link

INTERNAL SERVER ERROR /api/v1/doc/resources/?api_key=special-key #64

Closed abdulwahid24 closed 10 years ago

abdulwahid24 commented 10 years ago

I have trouble while displaying api docs and i followed every single steps mentioned on http://django-tastypie-swagger.readthedocs.org/en/latest/. But failed to load resource api doc. Need your help to fix this.

Here are my details

===========Packages=============== Django - 1.7b1 Python - 2.7.4 django-tastypie-mongoengine - 0.4.5 - active django-tastypie-swagger - 0.1.3 - active django-tastypie - 0.11.0 mongoengine - 0.8.7

================api.py========================= from mongoengine import * from mongoengine.django.auth import User

class Profile(Document):

GENDER = (('male','Male'),('female','Female'))
MARITAL_STATUS = (('single','Single'),('married','Married'))

user = ReferenceField(User)
dob = DateTimeField()
dob_image = ImageField(collection_name='images', thumbnail_size=(100,114))
gender = StringField(max_length=10, choices=GENDER)
marital_status = StringField(max_length=10, choices=MARITAL_STATUS)
contact_number = StringField(max_length=12)
alternate_number = StringField(max_length=12)

==============urls.py=========================== from django.conf.urls import patterns, include, url from django.contrib import admin

from tastypie.api import Api from users.api import UserResource, ProfileResource

v1_api = Api(api_name='v1') v1_api.register(UserResource()) v1_api.register(ProfileResource())

admin.autodiscover()

urlpatterns = patterns('',

Examples:

# url(r'^$', 'educator.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include(v1_api.urls)),
url(r'api/v1/doc/', include('tastypie_swagger.urls', namespace='tastypie_swagger'),kwargs={'tastypie_api_module':v1_api, 'namespace':'tastypie_swagger'}),

)

====================setttings.py================= TASTYPIE_API_MODULE = 'educator.urls.v1_api'

Below is what i am getting while hitting the url "http://localhost:8000/api/v1/doc/". 500 : INTERNAL SERVER ERROR /api/v1/doc/resources/?api_key=special-key screenshot from 2014-04-18 09 30 24

johnraz commented 10 years ago

Hi,

We will need the traceback of the 500 to be able to help you ;)

abdulwahid24 commented 10 years ago

Here is the complete stack trace.

Environment:

Request Method: GET Request URL: http://localhost:8000/api/v1/doc/resources/?api_key=special-key

Django Version: 1.7b1 Python Version: 2.7.4 Installed Applications: ('django.contrib.admin', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'mongoengine.django.mongo_auth', 'tastypie', 'tastypie_mongoengine', 'tastypie_swagger') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback: File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1. response = wrapped_callback(request, _callback_args, *_callback_kwargs) File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  2. return self.dispatch(request, _args, *_kwargs) File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  3. return handler(request, _args, *_kwargs) File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/django/views/generic/base.py" in get
  4. context = self.get_context_data(**kwargs) File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/tastypie_swagger/views.py" in get_context_data
  5. apis = [{'path': '/%s' % name} for name in sorted(self.tastypie_api._registry.keys())] File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/tastypie_swagger/views.py" in tastypie_api
  6. path, attr = tastypie_api_module.rsplit('.', 1)

Exception Type: AttributeError at /api/v1/doc/resources/ Exception Value: 'Api' object has no attribute 'rsplit'

abdulwahid24 commented 10 years ago

Hey, i resolved it finally,

I was passing Api instance directly to tastypie_api_module but it expect complete path to this instance.

This was my old code with error. url(r'api/v1/doc/', include('tastypie_swagger.urls', namespace='tastypie_swagger'),kwargs={'tastypie_api_module':v1_api, 'namespace':'tastypie_swagger'}),

And resolved code is url(r'api/v1/doc/', include('tastypie_swagger.urls', namespace='tastypie_swagger'),kwargs={'tastypie_api_module':'mysite.urls.v1_api', 'namespace':'tastypie_swagger'}),

Thanks alot... Awesome work done by you guys....really appreciated :)

johnraz commented 10 years ago

Glad you found the issue, will try to add a more meaningful message there.