Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django caching requests regardless of settings
I' have a page called 'results.html' from which a user can submit a form. The problem is that sometimes I submit the form and the response is taken from the cache, and other times it actually calls the response method in views.py. Here's an example: User submits 'The Imitation Game': the correct response is returned to the user and my response function in views prints [19/Nov/2016 00:50:21] "POST /results/ HTTP/1.1" 200 2414 Response function called!! Search term: The Imitation Game` to the console. However, if the user searches this again (or any other search term he/she searched in the past) this is the response: [19/Nov/2016 00:51:05] "GET /get_data?query=The%20Imitation%20Game HTTP/1.1" 200 18858 Clearly the response method was not called at all. This is also very evident on the front end because out-of-date data is returned to the user on subsequent requests. The kicker here is that I am using a dummy cache: # Use dummy cache for development and testing CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', }, 'deployment': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', } } and DEBUG = True. I am also marking the response method as follows: @never_cache def results(request): I cleared my browser cache, so it's not that either. I'm … -
Transferring GeoJson data to MongoDB modeling from Django Models
My Django project is currently set up with MongoEngine to connect to my MongoDB database. I'm working on the map data loading and right now depends from a Geojson file. Being new in working with MongoDB to use in creating a collection based from an existing file I would like to know if it's possible to transfer Geojson data based from my existing model.py For example I have this snippet of Geojson data: { "type" : "FeatureCollection", "features" : [ { "type" : "Feature", "route_id" : "ROUTE_880801", "geometry" : { "type" : "LineString", "coordinates" : [[120.9834301, 14.60350785], [120.9924853, 14.60077731], [121.005038, 14.60173248], [121.017, 14.6042], [121.026, 14.6105], [121.034, 14.6136], [121.043, 14.6185], [121.053, 14.6227], [121.065, 14.628], [121.073, 14.631], [121.086, 14.6223]] }, "properties" : { "name" : "name1" } } , { "type" : "Feature", "route_id" : "ROUTE_880801", "geometry" : { "type" : "LineString", "coordinates" : [[121.086, 14.6223], [121.073, 14.631], [121.065, 14.628], [121.053, 14.6227], [121.043, 14.6185], [121.034, 14.6136], [121.026, 14.6105], [121.017, 14.6042], [121.005038, 14.60173248], [120.9924853, 14.60077731], [120.9834301, 14.60350785]] }, "properties" : { "name" : "name2" } } ] } and my models.py from mongoengine import * from colorful.fields import RGBColorField class Line(Document): id = StringField(required=True) rLine = LineStringField() name = StringField(required=True) color = RGBColorField() … -
Django MySQL server has gone away
I have a django site the was using sqlite for the backend, recently we upgraded to MySQL and now are receiving intermittent 'MySQL server has gone away' errors. After starting the site it loads fine, clicking around to change pages will result in the error usually after viewing 1 to 6 pages. The page it occurs on appears to be irrelevant, the same page may load fine the first time but throw the error the 2nd time. Here's my environment Nginx running on host machine as reverse proxy Docker container running Nginx inside, Django 1.8, uwsgi, and Python 3.4. Django is using the mysqlclient db driver. Google Cloud MySQL, 2nd generation I've tried using a local MySQL server rather than the Google Cloud MySQL, it didn't make a difference. I also tried using the MySQL Connector/Python DB driver instead of mysqlclient. It produced a different (but similar) error message and traceback. If I go back to sqlite, it works fine. Running under the django development server rather than nginx also works fine. I've seen posts for this error stating that the django CONN_MAX_AGE should be less than the MySQL wait_timeout, but I'm using the default CONN_MAX_AGE setting of 0. According … -
Extra fields Django-registration Forms
Good evening, I am using django-registration for a Web application; By using this, the form that has default django-registration only has 4 fields (username, email, password, repeat password). How to add more fields to this form and store them in the database correctly? Thank you. -
Filter objects with empty generic content
My notification model is generic, meaning it can hold any object. It looks like this: class Notification(models.Model): receiver = models.ForeignKey(User, related_name='notifications') sender = models.ForeignKey(User, related_name='sent_notifications', blank=True, null=True) object_type = models.ForeignKey(ContentType, blank=True, null=True) object_id = models.PositiveIntegerField(blank=True, null=True) object = GenericForeignKey('object_type', 'object_id') type = models.CharField(max_length=3, choices=config.NOTIFICATION_TYPE_OPTIONS) unread = models.BooleanField(default=True) slug = models.SlugField(max_length=255, unique=False, default='notification') # Other date_created = models.DateTimeField(auto_now=False, auto_now_add=True, blank=True) date_modified = models.DateTimeField(auto_now=True, auto_now_add=False, blank=True) Whenever a user deletes an object that a notification relates to, it ends up pointing to a NoneType object instead. I want to filter out Notifications that don't relate to anything to the user. I've already tried: Notification.objects.exclude(object=None) and Notification.objects.filter(object=None) However both gives me an error that I cannot do a reverse relationship query on generic content type objects. How do I filter or get all Notifications that are pointing to non-existing objects? -
Use SQLite for Django locally and Postgres on server
I am starting with Django development as a hobby project. So far I have happily worked with SQLite, both in development (i.e. with py manage.py runserver) and in deployment (on Nginx + uWSGI). Now I would also like to learn to use a more robust PostgreSQL database. However, if possible, I would like to skip installing it locally, to avoid installing Postgres on Windows. I was wondering if it was possible, by means of Django, to use SQLite whenever I use the built-in server and Postgres in deployment, without changing the project code. Couldn't find how to do it. I can use a workaround and make my deployment procedure change the settings on server each time I deploy. But that's kind of a hack. -
How get multiple resultset / cursors with django and postgresql?
Taking the example from http://trentrichardson.com/2012/01/04/return-multiple-result-sets-with-php-and-postgresql-functions/, I wanna return multiple results to a view. I have this code now: CREATE OR REPLACE FUNCTION load_deuda(cobro CHAR) RETURNS setof refcursor AS $$ DECLARE c_cobro refcursor; DECLARE c_deudas refcursor; BEGIN OPEN c_cobro FOR SELECT * FROM "recaudo_cobro" ORDER BY "recaudo_cobro"."nombre" ASC; RETURN NEXT c_cobro; OPEN c_deudas FOR SELECT id, orden FROM cliente_deuda WHERE cobro_id=1 AND estado='ACTIVA' ORDER BY orden; RETURN NEXT c_deudas; END; $$ LANGUAGE plpgsql; def exeSql(cobro, tables, params=None): from django.db import models, connection sql = "SELECT load_deuda('%s');" % cobro; for i, table in enumerate(tables): sql += '\nFETCH ALL IN "<unnamed portal %d>";' % (i + 1) print(sql) with connection.cursor() as c: c.execute(sql) for i, table in enumerate(tables): yield c.fetchall() However, this return me the last cursor. How get all of them? -
Django: Search stopped working in 1.10
I've been working on an application I originally started in Django 1.7, then ported it over to 1.10, where it stopped working. It will work if I select a District to search by, but only by the District. What I'm hoping is that if all the search terms are left blank, it will return all objects in that pool. It would be great if anyone had some ideas on where this is going wrong, as it doesn't give me errors, just tells me there are no results. Model: class PlantingSite(models.Model): id_planting_site = models.IntegerField(null=True, blank=True) empty = models.BooleanField(default=False) address = models.CharField(max_length=256, null=True, blank=True) street = models.CharField(max_length=256, null=True, blank=True) coord_lat = models.CharField(max_length=256, null=True, blank=True) coord_long = models.CharField(max_length=256, null=True, blank=True) zipcode = models.CharField(max_length=256, null=True, blank=True) neighborhood = models.ForeignKey(Neighborhood, null=True) district = models.ForeignKey(District, null=True) property_address = models.CharField(max_length=256, null=True, blank=True) property_street = models.CharField(max_length=256, null=True, blank=True) property_zipcode = models.CharField(max_length=256, null=True, blank=True) property_owner = models.ForeignKey(Contact, related_name='planting_sites_owned_by_contact', null=True) contact = models.ForeignKey(Contact, related_name='planting_sites_cared_for_by_contact', null=True) notes = models.TextField(null=True, blank=True) basin_type = models.ForeignKey(BasinType, related_name='planting_sites_with_basin_type', null=True) overhead_utility = models.ManyToManyField(OverheadUtility, related_name='planting_sites_with_overhead_utility', blank=True) hardscape_damage = models.ManyToManyField(HardscapeDamage, related_name='planting_sites_with_hardscape_damage', blank=True) aspect = models.ForeignKey(Aspect, null=True) sequence = models.IntegerField(null=True, blank=True) side = models.CharField(max_length=256, null=True, blank=True) size = models.CharField(max_length=256, null=True, blank=True) created_by = models.ForeignKey(User, related_name='planting_sites_created', null=True) created_at = models.DateTimeField(default=timezone.now) … -
How to tell list from non-list in Django template?
I've got a Django template I'd sometimes like to pass a list and sometimes like to pass a single value. How can the template tell which it was given? I'm thinking the value would be set like one of these: context = { 'foo' : 'bar } or: context = { 'foo' : ['bar', 'bat', 'baz'] } Then, the template would have code that looks something like this: {% if foo isa list %} {% for item in foo %} {{ item }}<br> {% endfor %} {% else %} {{ item}}<br> {% endif %} I can set it up to have foo or foolist, for example, and check for one or the other. However, it'd be a bit nicer (imo) to just have foo that was either a list or not. -
Django 1.10.1 'my_templatetag' is not a registered tag library. Must be one of:
I want a menu thats custom depending which group you are member of. Im using Django 1.10.1, allauth and so on. When im trying to make my templatetag it fails and it says:¨ TemplateSyntaxError at / 'my_templatetag' is not a registered tag library. Must be one of: account account_tags admin_list admin_modify admin_static admin_urls cache i18n l10n log socialaccount socialaccount_tags static staticfiles tz 'my_templatetag.py' looks like this: from django import template from django.contrib.auth.models import Group register = template.Library() @register.filter(name='has_group') def has_group(user, group_name): group = Group.objects.get(name=group_name) return group in user.groups.all() and tha error comes in my .html file which say, {% load my_templatetag %} I have tried to restart the server like millions of times, also i tried to change all the names, and the app is a part of INSTALLED_APPS in settings.py. What am I doing wrong? -
Django Queryset compare two different models with multiple rows
I have these two models that I would like to return the sum of. I get an database error about the subquery returning more than one row. What would be the best way to compare both without using a for statement? AuthorizationT(models.Model) ar_id = models.BigIntegerField(blank=True, null=True) status_flag = models.BigIntegerField(blank=True, null=True) BillT(models.Model) paid_id = models.BigIntegerField(blank=True, null=True) recvd = models.FloatField(blank=True, null=True) Query I tried paidbill= BillT.objects.values_list('paid_id', flat=true) AuthorizationT.objects.values().filter(ar_id=paidbill, status_flag=0).aggregate(Sum('recvd')) In SQL I know it would be select sum(recvd) from authorization_t a, bill_t b where a.ar_billid0= b.paid_id and a.status_flag=0 I'm looking for the equivalent in queryset -
Problems with using django-crontab in Heroku (Django project)
it is impossible for me to run cron jobs using django-crontab in heroku. Cron job seems to run fine for me locally but failed in heroku server. Following this tutorial and it works fine without heroku (https://hprog99.wordpress.com/2014/08/14/how-to-setup-django-cron-jobs/) Let me share with you my codes: setting.py INSTALLED_APPS = [ 'django_crontab', # more codes ] CRONJOBS = [ ('0 0 * * *', 'cinemas.cron.hello') ] cinemas/cron.py def hello(): print('This job is run every day at 12am.') finally i ran this: python manage.py crontab add However, heroku produce this error message: /var/spool/cron: No such file or directory seems like there is no cron directory in heroku? Anyway around this if I were to use django-crontab in heroku? Thanks -
django django-allauth save extra_data from social login in signal
Setup I'm using Django 1.8.15 and django-allauth 0.28.0 Description What I want to do is pretty easy to explain: If a user logs in via social media (facebook, google+ or twitter) i want to retrieve the extra_data from sociallogin to get the url to the avatar and other information to store it in my Profile, which is a One-to-one relation to my User model. My approaches 1) First I added a class with pre_social_login like here which gets called after the user has signed in via social media. models.py class SocialAdapter(DefaultSocialAccountAdapter): def pre_social_login(self, request, sociallogin): """Get called after a social login. check for data and save what you want.""" user = User.objects.get(id=request.user.id) # Error: user not available profile = Profile(user=user) picture = sociallogin.account.extra_data.get('picture', None) if picture: # ... code to save picture to profile settings.py SOCIALACCOUNT_ADAPTER = 'profile.models.SocialAdapter' I want to get the instance from the user but it seems, that it wasn't created yet. So I tried the following: 2) I have another signal which creates a profile if a new user is added: models.py @receiver(post_save, sender=settings.AUTH_USER_MODEL) def create_profile_for_new_user(sender, created, instance, **kwargs): """Signal, that creates a new profile for a new user.""" if created: profile = Profile(user=instance) # following … -
Why can't I update pip on Windows 7?
I downloaded pip from the pip website and ran it on Python IDLE 3.4. When I did that, it says You are using pip version 6.0.8, however version 9.0.1 is available. So I tried to upgrade it on command prompt using python -m pip install --upgrade pip but then this came up: Could not find a version that satisfies the requirement install (from versions : ) No matching distribution found for install Why doesn't it let me update pip? -
Django - How can I debug code which POST's when a bug seems to be in the view?
I thought I would ask a broad question so I get a better understanding of Django and can more readily deal with any similar problems I may encounter. The specific issue which I am having is that I have written my first formset code, which renders the forms correctly but when posted no new objects are created. I can see from the server that the form has been posted, I get no errors but no data has been added to my database (checked from django admin and manage.py shell). Perhaps it is possible to read what has been posted in a manage.py shell? I would like to be able to check whether the form posted its data correctly and it has been received by the view. Then I can see why either the data isn't posting correctly or the view isn't handling it correctly. For the specific issue I will place my code below, in case it's a simple beginner error which one of you wizards can spot. I tried to follow and adapt this tutorial for my own purposes. Models.py class Chunk(models.Model): name = models.CharField(max_length=250) text = models.CharField(max_length=500) images = models.FileField() question = models.CharField(max_length=250) expected_completion_time = models.IntegerField(default=1) keywords = … -
ImportError: No module named tablecheck.wsgi when starting up django/uwsgi app
I am trying start up an django app that someone else wrote. I get: ImportError: No module named tablecheck.wsgi Relevant part of the settings.py file looks like this: # Application definition INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'suit', 'tablecheck', 'django.contrib.admin', 'moderation', 'django_evolution' ) In the current dsubdir of the release dir, I do have a directory called table check which seems to have the codes necessary: /somedir/tablecheck# ls -lrt total 92 -rw-r--r-- 1 bi bi 395 Apr 9 2015 wsgi.py -rw-r--r-- 1 bi bi 1028 Apr 9 2015 views.py -rw-r--r-- 1 bi bi 483 Apr 9 2015 urls.py drwxr-xr-x 3 bi bi 4096 Apr 9 2015 templates -rw-r--r-- 1 bi bi 1140 Apr 9 2015 readonly.py -rw-r--r-- 1 bi bi 1019 Apr 9 2015 moderator.py -rw-r--r-- 1 bi bi 0 Apr 9 2015 __init__.py -rw-r--r-- 1 bi bi 1600 Apr 9 2015 admin.py -rw-r--r-- 1 bi bi 1406 Apr 11 2015 views.pyc -rw-r--r-- 1 bi bi 689 Apr 11 2015 urls.pyc -rw-r--r-- 1 bi bi 1858 Apr 11 2015 readonly.pyc -rw-r--r-- 1 bi bi 1077 Apr 11 2015 moderator.pyc -rw-r--r-- 1 bi bi 2188 Apr 11 2015 admin.pyc -rw-r--r-- 1 bi bi 6392 Jan 22 2016 models.py -rw-r--r-- … -
How to make UserCreationForm email field required
I am a newbie in Django. I would like the email field in the subclassed UserCreationForm to be required. I have tried the commented methods but none has worked so far. I have tried the solution from this but to no avail. Any help would be appreciated. class MyRegistrationForm(UserCreationForm): captcha = NoReCaptchaField() #email = forms.EmailField(required=True, widget=forms.TextInput(attrs={'class': 'mdl-textfield__input'})) class Meta: model = User fields = ('first_name', 'last_name', 'username', 'email', 'password') #email = { # 'required': True #} widgets = { 'first_name': forms.TextInput(attrs={'class': 'mdl-textfield__input'}), 'last_name': forms.TextInput(attrs={'class': 'mdl-textfield__input'}), 'username': forms.TextInput(attrs={'class': 'mdl-textfield__input'}), #'email': forms.TextInput(attrs={'class': 'mdl-textfield__input'}) } def save(self, commit=True): user = super(MyRegistrationForm, self).save(commit=False) user.first_name = self.cleaned_data["first_name"] user.last_name = self.cleaned_data["last_name"] user.username = self.cleaned_data["username"] user.email = self.cleaned_data["email"] #user.user_level = self.cleaned_data["user_level"] if commit: user.save() return user def __init__(self, *args, **kwargs): super(MyRegistrationForm, self).__init__(*args, **kwargs) self.fields['password1'].widget.attrs['class'] = 'mdl-textfield__input' self.fields['password2'].widget.attrs['class'] = 'mdl-textfield__input' #self.fields['email'].required=True -
Having strange decimal.InvalidOperation exception with PyPDF2 and Django
I am having a strange problem with PyPDF in my Django Application written in python 3. First, this problem only occur when I am running the application via nginx + gunicorn + wsgi. When I run it in my test environment via python manage.py runserver:0.0.0.0:8000 this problem doesn't happen at all. The problem happens when I call PdfFileReader.numPages, but always there is another Exception being raised and this error appears after the During handling of the above exception, another exception occurred: The exceptions that happens before this messeges are: Traceback (most recent call last): File "/home/django/.virtualenvs/womou/lib/python3.4/site-packages/PyPDF2/generic.py", line 229, in __new__ return decimal.Decimal.__new__(cls, utils.str_(value), context) File "/home/django/.virtualenvs/womou/lib/python3.4/site-packages/PyPDF2/utils.py", line 252, in str_ if sys.version_info[0] < 3: File "/home/django/.virtualenvs/womou/lib/python3.4/site-packages/gunicorn/workers/base.py", line 159, in handle_abort sys.exit(1) SystemExit: 1 and Traceback (most recent call last): File "/home/django/.virtualenvs/womou/lib/python3.4/site-packages/PyPDF2/generic.py", line 229, in __new__ return decimal.Decimal.__new__(cls, utils.str_(value), context) File "/home/django/.virtualenvs/womou/lib/python3.4/site-packages/gunicorn/workers/base.py", line 159, in handle_abort sys.exit(1) SystemExit: 1 Important to note that the second one is more common then the first. Then, after those exceptions, I get the same one: During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/django/.virtualenvs/womou/lib/python3.4/site-packages/django/core/handlers/base.py", line 132, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/django/.virtualenvs/womou/lib/python3.4/site-packages/django/contrib/auth/decorators.py", line 22, in … -
Why does my Django project throw an ImportError: no module named my_project.wsgi?
I'm trying to run a local Django/Nginx project using docker-compose. I am receiving the following error after docker-compose up: self.wsgi = self.app.wsgi() File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load return self.load_wsgiapp() File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp return util.import_app(self.app_uri) File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 357, in import_app __import__(module) ImportError: No module named my_project.wsgi [2016-11-18 02:58:22 +0000] [9] [INFO] Worker exiting (pid: 9) [2016-11-18 02:58:22 +0000] [1] [INFO] Shutting down: Master [2016-11-18 02:58:22 +0000] [1] [INFO] Reason: Worker failed to boot. I'm not 100% sure, but I believe the offending line is in my docker-compose here: command: /usr/local/bin/gunicorn my_project.wsgi:application -w 2 -b :8000 Here is my full Docker-Compose: web: restart: always build: ./web expose: - "8000" links: - postgres:postgres - redis:redis volumes: - /usr/src/app - /usr/src/app/static env_file: .env environment: DEBUG: 'true' command: /usr/local/bin/gunicorn my_project.wsgi:application -w 2 -b :8000 nginx: restart: always build: ./nginx/ ports: - "80:80" volumes: - /www/static volumes_from: - web links: - web:web postgres: restart: always image: kartoza/postgis:9.4-2.1 ports: - "5432:5432" volumes: - pgdata:/var/lib/postgresql/data/ redis: restart: always image: redis:latest ports: - "6379:6379" volumes: - redisdata:/data My directory structure: docker-compose.yml web/ Dockerfile manage.py my_project/ __init__.py settings.py urls.py wsgi.py accounts_app/ My wsgi.py: import os from … -
passing a multidimentional js array to views when django from post
I'm making a web page where students can understand the way calculus ecuations. Using Jquery UI they can drag and drop formulas, write results to the ecuations and add more ecuations (which are steps to resolving the first one). (calculus 1) I have a model in django that relates to itself, and to another simple table: class Procedimiento(models.Model): regla = models.CharField(max_length=250) class Ecuacion(models.Model): expresion = models.CharField(max_length=140) procedimiento = models.ForeignKey(Procedimiento, blank=True, null=True) padre = models.ForeignKey('self', blank=True, null=True, related_name='resultado') In my html a jquery function that adds new forms dynamically (http://stackoverflow.com/a/8097617/6731917). I created a 'map' (a multidimensional array) to help me create the right relationships to self in my views file. The question is, how I pass this assay when the user press the submit bottom? The kind of relationship that I will be mapping is: image example of problem If you think there is a better way of doing this please let me know -
django fileupload form fails to submit and upload
I'm trying to upload a file from a form which is one of serveral forms with django wizard view. However when I upload a file and click submit, the file just dissapears and I get a 'This field is required' error. Models.py class Bill(models.Model): service = models.ForeignKey(UserService) bill = models.FileField(upload_to='bills', validators=[validate_file_extension]) raw_data = models.TextField(null=True) meta_data = models.TextField(null=True) Forms.py class BillUploadForm(forms.ModelForm): class Meta: model = models.Bill fields = ['bill'] views.py SIGNUP_FORMS = [ ('signup', SignupForm), ('address', AddressForm), ('direct_debit', UserDirectDebitForm), ('account', AccountForm), ('user_service', UserServiceForm), ('bill_upload', BillUploadForm), ] TEMPLATES = { 'signup': 'site/signup.html', 'address': 'site/signup_address.html', 'direct_debit': 'site/signup_directdebit.html', 'account': 'site/signup_directdebit.html', 'user_service': 'site/signup_directdebit.html', 'bill_upload': 'site/signup_directdebit.html', } class SignupWizard(SessionWizardView): location = os.path.join(settings.MEDIA_ROOT, 'temp', 'files') file_storage = FileSystemStorage(location) def get_template_names(self): return [TEMPLATES[self.steps.current]] def dispatch(self, request, *args, **kwargs): if request.user.is_authenticated(): return redirect(settings.LOGIN_REDIRECT_URL) return super().dispatch(request, *args, **kwargs) def done(self, form_list, form_dict, **kwargs): cd = form_dict['signup'].cleaned_data user = User.objects.create_user( username=cd['email'].split('@')[0], email=cd['email'], password=cd['password1'], first_name=cd['first_name'], last_name=cd['last_name'], ) user.save() address = form_dict['address'].save(commit=False) address.user = user address.save() direct_debit = form_dict['direct_debit'].save(commit=False) direct_debit.user = user direct_debit.save() account = form_dict['account'].save(commit=False) account.address = address account.payment = direct_debit account.save() user_service = form_dict['user_service'].save(commit=False) user_service.account = account user_service.save() bill_upload = form_dict['bill_upload'].save(commit=False) bill = form_dict['bill_upload'].cleaned_data['bill'] bill_upload.bill = bill bill_upload.service = user_service bill_upload.save() self.file_storage.delete(bill.name) complete_signup(self.request, user, settings.ACCOUNT_EMAIL_VERIFICATION, settings.LOGIN_REDIRECT_URL) return redirect(settings.LOGIN_REDIRECT_URL) -
lookup fields with null value in django rest API query params
I Want to pass a null value in query params when calling a Django rest API. https://omapi-dev.herokuapp.com/v1/teachingships/969af7f85633/?teacher=null when I use this it returns empty list and when I use https://omapi-dev.herokuapp.com/v1/teachingships/969af7f85633/?teacher__isnull=True It returns all objects irrespective of that whether the teacher is null or not. Teacher is a foreign key in database -
Amazon RDS connects to localhost fine, but doesnt work on EC2?
When running the database on localhost it works fine. You can add/remove people etc on django. But when i deploy on eb it doesnt seem to work even though it works perfectly fine on localhost.Thanks! -
RapidSMS Twilio Django - SMS Application Architecture
I am learning SMS application dev with RapidSMS Django. I came across rapidsms-twilio for backend. I am lost here and trying to make sense of overall architecture and technologies associated with each layer. It will help me in future research of better alternatives. Similar to web applications JS/Ajax/css/html are front end tech with java in app layer and db on backend how could i layout SMS application framework? From my understanding Twilio will provide a number so whenever text is received on number it will receive it in SMMP format and convert it to HTTP and call app server URL mapped against it which could be in django. Where and what does rapidsms do here? -
Error while converting token Django rest-framework Social Oauth2
I am trying to set up REST API with social authentication. I am using Django rest-framework Social Oauth2 . However when I am making a POST request to http://localhost:8000/auth/convert-token data = { client_id = my_client_id, client_secret = client_secret, grant_type = convert_token, backend = facebook, token = User token from https://developers.facebook.com/tools/accesstoken/} This is resulting in error: "POST /auth/convert-token HTTP/1.1" 400 76 Internal Server Error: /auth/convert-token Traceback (most recent call last): File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/django/core/handlers/exception.py", line 39, in inner response = get_response(request) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/django/core/handlers/base.py", line 187, in _get_response response = self.process_exception_by_middleware(e, request) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view return view_func(*args, **kwargs) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view return self.dispatch(request, *args, **kwargs) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/django/utils/decorators.py", line 67, in _wrapper return bound_func(*args, **kwargs) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view return view_func(*args, **kwargs) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/django/utils/decorators.py", line 63, in bound_func return func.__get__(self, type(self))(*args2, **kwargs2) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/braces/views/_forms.py", line 21, in dispatch return super(CsrfExemptMixin, self).dispatch(*args, **kwargs) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/rest_framework/views.py", line 477, in dispatch response = self.handle_exception(exc) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/rest_framework/views.py", line 437, in handle_exception self.raise_uncaught_exception(exc) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/rest_framework/views.py", line 448, in raise_uncaught_exception raise exc File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/rest_framework/views.py", line 474, in dispatch response = handler(request, *args, **kwargs) File "/home/kuba/.virtualenvs/test/lib/python3.5/site-packages/rest_framework_social_oauth2/views.py", line 41, in post url, headers, body, …