Forums

Django rest framework

It possible to create a webapp with the django-rest-framework?

I tried to install it like in theirs quickexample: http://www.django-rest-framework.org/tutorial/quickstart And it says: pip install djangorestframework ... creating /usr/local/lib/python2.7/dist-packages/rest_framework error: could not create '/usr/local/lib/python2.7/dist-packages/rest_framework': Permission denied ...

So I cannot write there because Im not superuser, I accept it :P. Its any other way to make that framework working?

Fixed, sorry, my fault.

added --user pwich to pip install command and working

Excellent, glad to hear you got it working :-)

added --user pwich to pip install command and working ..?

how to run pip command with different user , i am facing this same problem but not able to solve , how to solve this ??

What error message are you getting? Could you post the exact command that you're trying, and what the error message is?

Thanks giles for replying i am getting this error msg in my error.log file

File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 162, in _fetch
   app = import_module(appname)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
 __import__(name)
django.template.base.TemplateSyntaxError: Caught ImportError while rendering: No module named rest_framework

and i have install vitrual env for upgrade the djnago version . i am using django 1.6 , and i have install rest_framework in virtual env , so while running my project i am getting this error.

[edited by admin: formatting]

Can I take a look at your files? That might make it easier to debug.

this is my setting.py file

BUILT_INS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', )

THIRD_PARTY_APPS = ( 'casper', 'widget_tweaks', 'django_coverage', 'social.apps.django_app.default', 'rest_framework', )

CUSTOM_APPS = ( 'dashboard', 'generator', 'shorturl', 'api', )

INSTALLED_APPS = BUILT_INS + THIRD_PARTY_APPS + CUSTOM_APPS

Middleware

MIDDLEWARE_CLASSES = ( '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', )

Authentication

AUTHENTICATION_BACKENDS = ( 'social.backends.google.GoogleOAuth2', 'social.backends.twitter.TwitterOAuth', 'social.backends.facebook.FacebookOAuth2', #'social.backends.facebook.FacebookAppOAuth2', #'social.backends.google.GoogleOpenId', #'social.backends.google.GoogleOAuth', 'django.contrib.auth.backends.ModelBackend', )

Some other stuff

TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + ( 'social.apps.django_app.context_processors.backends', 'social.apps.django_app.context_processors.login_redirect', )

ROOT_URLCONF = 'qrcvault.urls'

WSGI_APPLICATION = 'qrcvault.wsgi.application'

Database

https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } }

Internationalization

https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

Static files (CSS, JavaScript, Images)

https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

python-social-auth settings

http://psa.matiasaguirre.net/

django-rest-framework stuff

REST_FRAMEWORK = { # Use hyperlinked styles by default. # Only used if the serializer_class attribute is not set on a view. 'DEFAULT_MODEL_SERIALIZER_CLASS': 'rest_framework.serializers.HyperlinkedModelSerializer',

# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
    'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]

}

Sorry, I should have been clearer -- I can look at the files in your private disk storage from here, and that might make it easier to work out what the problem is. But I need your permission before I can look at your files. If you just post here saying "yes" then that's enough :-)

yes you can , thanks for support.

OK, I can see that you have a virtualenv with the Django REST framework installed, but it doesn't look like you're activating the virtualenv in your WSGI file (linked from the Web tab). It should look something like the one in this tutorial.

thanks giles for your support .

I am not able to get what do you mean by "added --user pwich to pip install command and working"?

If I am a normal site user, how can i use pip install, please let me know the entire command.

Let's say you want to install the package aafigure. Here's what you'd do:

  • Start a bash console
  • Run this command:

    pip install --user aafigure

The above problem is resolved for me.

But, when I incidude 'rest_framework' in INSTALLED_APPS, it continuously gives 'ImportError: No module named 'rest_framework''

Kindly help on this if I am missing out something

Ah, I see you're using Python 3.4 for your web app. So the command to install the Django rest framework is slightly different:

pip3.4 install --user djangorestframework

right this was working for me :)

I am following this blog post to create a sample restframework app-

http://petecole.wordpress.com/2012/05/22/creating-a-rest-service-using-python-and-django/comment-page-1/#comment-11

but I am getting this error --

'AttributeError

Exception Value:
'list' object has no attribute 'get''

Pls see this if you can help me out.

It's hard to debug with just that error message. Could you point me to a page on the site which is showing the problem?

ya sure--

http://heyswati06.pythonanywhere.com/Data/Orders/

OK. So if you look at that traceback, the line inside Django's internal code that is showing the problem looks like this:

if response.get('X-Frame-Options', None) is not None:

The error is 'list' object has no attribute 'get'. So that means that the Django is getting confused because it has a list object (which doesn't have a get method) instead of a HttpResponse object (which does have one).

My guess is that somewhere you're returning a list from a regular view, instead of from a subclass of the djangorestframework.views.View type that the rest framework provides.