Django: Django-Rest-Framework gives Attribution error (pagination) - python

I'm trying to create migrations of a project which uses Rest Framework pagination.
But I'm getting error as Attribution error: 'module' object has no attribute BasePaginationSerializer. I have tried uninstalling-resinstalling the said versions of Python, Django and RestFramework. But I still get that error.
Here's the screenshot of terminal showing error.
Here's a chunk of the code present in paginator.py
import urlparse
from django.core.paginator import EmptyPage, Page, PageNotAnInteger, Paginator
from django.utils.http import urlencode
from rest_framework import serializers, pagination
class CustomPaginationSerializer(pagination.BasePaginationSerializer):#Here it shows the error.
meta = MetaSerializer(source='*')
results_field = 'objects'
Can someone help me out in getting this issue resolved?
Info:
- Here's the project which I'm trying to build. https://github.com/mozilla/zamboni
I'm using Ubuntu 15.10
Python - 2.7.10
Django - 1.8.7

Django Rest Framework doesn't provide anything like BasePaginationSerializer, that's why you're getting an error - because it doesn't exist. You probably want to use BasePagination

Related

How can i solve syntax error during making webapp?

im working with django and making webapp now this has occurred
def Notes(generic.DetailView):
^
Error invalid syntax
Function name:NotesDetaiView
It should look like this. Check the documentation.
from django.views.generic.detail import DetailView
from .models import Notes # or other location
class NotesDetailView(DetailView):
model = Notes
# rest of code

save() doesn't work in Mongoengine

I'm trying to perform a simple insert operation using Mongoengine and Django.
Regarding my project structure simply I have a project, AProject and an app, AnApp. I have a running mongo in a remote machine with an IP of X.X.X.X. I am able to insert document using Robomongo in it.
I have removed the default Database configuration part of the settings.py located inside the AProject directory. The newly added lines are shown below:
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
import mongoengine
# ----------- MongoDB stuff
from mongoengine import register_connection
register_connection(alias='default', name='AProject', host='X.X.X.X')
# ----------
Now let me show the models.py and the views.py located inside AnApp.
models.py
from mongoengine import Document, StringField
class Confession(Document):
confession = StringField(required=True)
views.py
from django.http import HttpResponse
from models import Confession
from mongoengine import connect
def index(request):
connect('HacettepeItiraf', alias='default')
confession = Confession()
confession.confession = 'First confession from the API'
print(confession.confession + ' Printable') # The output is --First confession from the API Printable--
print(confession.save()) # The output is --Confession object--
return HttpResponse(request)
The urls.py located inside AProject is simply as below:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^confessions/', include('confession.urls')),
url(r'^admin/', admin.site.urls),
]
When I enter http://127.0.0.1:10000/confessions/ I see a blank screen which I expect. However there is nothing saved from the API. I get the expected output except Confession object.
How can I solve this problem?
EDIT:
I found the concrete proof that currently MongoEngine's support for Django is unstable and it is corresponding to Django version 1.9:
MongoEngine documentation on Django support states:
Django support has been split from the main MongoEngine repository. The legacy Django extension may be found bundled with the 0.9 release of MongoEngine.
and
6.1. Help Wanted!
The MongoEngine team is looking for help contributing and maintaining a new Django extension for MongoEngine! If you have Django experience and would like to help contribute to the project, please get in touch on the mailing list or by simply contributing on GitHub.
Which leads to this repo, where the following is stated:
THIS IS UNSTABLE PROJECT, IF YOU WANT TO USE IT - FIX WHAT YOU NEED
Right now we're targeting to get things working on Django 1.9
So it may be possible that it cannot play well with Django at this state or with your version and thus the problem occurs.
Initial attempt, leaving it here for legacy reasons.
I believe that the problem occurs on how you are initializing your object, although I do not have a set up to test this theory.
It is generally considered that is better to make a new object with the .create() method:
def index(request):
connect('HacettepeItiraf', alias='default')
confession = Confession.objects.create(
confession='First confession from the API'
)
print(confession.confession + ' Printable')
confession.save()
return HttpResponse(request)
Have a look at the Django & MongoDB tutorial for more details.
In this tutorial, the supported Django version is not mentioned, but I haven't found concrete proof that MongoDB Engine can or can't play well with Django version > 1.8.
Good luck :)

cloudinary django database error

I am developing app that uses Cloudinary, using Django 1.8.
I downloaded the sample project from https://github.com/cloudinary/cloudinary-django-sample.
This line:
image = CloudinaryField('image')
causes an error when runnig "manage.py migrate" saying
django.db.utils.OperationalError: near "None": syntax error
Tried adding "null=True" and "blank=True" to the field definition
image = CloudinaryField('image', null=True, blank=True)
but I am getting the same result.
I import cloudinafield like this
from cloudinary.models import CloudinaryField
When I comment out the line with CloudinadyField there are no errors.
What can be the reason of this error?
Well, there is no such field type like the one you used.
For handling image you can either use CharField to store the url or use FileField to store the file key which will link the url.
You can find detailed configuration on this page.
I feel like an idiot, just updated cloudinary library to 1.1.3 and everything works fine now. Thanks Tal Lev-Ami

django-cms: reverse url to an/another apphook - multilingual

I have two apphooks (on a multilingual page) and need create one url with url reverse to the other apphook, but it gives me a
NoReverseMatch
Error.
Any ideas how to fix it?
Django CMS version: 2.4.3
Django version 1.5.5
These are my apphook files of one (working) apphook, the other one is quite similar.
cms_app.py:
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _
class ProjectsAppHook(CMSApp):
name = _("Projects")
urls = ["projects.urls"]
apphook_pool.register(ProjectsAppHook)
views.py:
def projectsCategoryOverview(request):
projectCategories=ProjectCategory.objects.all().order_by('name').select_related()
#return render(request,'projectCategoryOverview.html', {'projectcategories': projectCategories})
return render_to_response('projectCategoryOverview.html',
{'projectcategories': projectCategories},
context_instance=RequestContext(request))
ok I'v found the problem.
I haven't created the page to which it should link to in the language the source page was displayed.

django-facebook internal code saying it can't find facebook_id

I've followed the tutorial and the examples for django-facebook from https://github.com/tschellenbach/Django-facebook/tree/master/facebook_example
I've got it up and running (as in i've run syncdb and migrations, and integrated the javascript and css code into my template).
When I click the link in my template, it successfully connects to Facebook and I can authorize. However, when it redirects, I get an error:
Request Method: POST
Request URL: http://127.0.0.1:8000/facebook/connect/?facebook_login=1
Django Version: 1.5.1
Exception Type: AttributeError
Exception Value: user or profile didnt have attribute facebook_id
Exception Location: /usr/local/lib/python2.7/dist-packages/django_facebook/utils.py in get_user_attribute, line 109
Python Executable: /usr/bin/python
Python Version: 2.7.3
This is within django-facebook's code, and I'm not sure if I've done something wrong with my setup. I've created my own UserProfile model which extends the abstract FacebookProfileModel class (I've tried using FacebookModel as well):
from django_facebook.models import FacebookProfileModel
from django.db.models.signals import post_save
class UserProfile(FacebookProfileModel):
user = models.OneToOneField('auth.User')
def create_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_profile, sender=User)
I can see the profile get created in the db, although it's all nulls (except for the user id used in the foreign key). Not sure what I'm doing wrong, any pointers?
I found out what was wrong, and want to post the solution back. The problem was that I didn't specify AUTH_PROFILE_MODULE in my settings.py. In the django-facebook documentation, it didn't mention that when it gave the option to extend the profile class, so I missed it. Silly mistake!

Categories