django-2.2

Delete an object automatically after 5 minutes

别来无恙 提交于 2021-02-19 16:05:06
问题 I'm trying to create a function that automatically delete an object after 5 minutes from publication. from django.contrib.gis.db import models from django.utils import timezone import datetime class Event(models.Model): name = models.CharField( max_length=100, ) publishing_date = models.DateTimeField( default=timezone.now, blank=True, ) @property def delete_after_five_minutes(self): time = self.publishing_date + datetime.timedelta(minutes=5) if time > datetime.datetime.now(): e = Event

Delete an object automatically after 5 minutes

旧巷老猫 提交于 2021-02-19 15:55:50
问题 I'm trying to create a function that automatically delete an object after 5 minutes from publication. from django.contrib.gis.db import models from django.utils import timezone import datetime class Event(models.Model): name = models.CharField( max_length=100, ) publishing_date = models.DateTimeField( default=timezone.now, blank=True, ) @property def delete_after_five_minutes(self): time = self.publishing_date + datetime.timedelta(minutes=5) if time > datetime.datetime.now(): e = Event

NoReverseMatch error from Python Tutorial

╄→гoц情女王★ 提交于 2021-02-11 05:59:23
问题 Django Tutorial part 4 I am getting a NoReverseMatch at /polls/1/ NoReverseMatch at /polls/1/ Reverse for 'polls.index' not found. 'polls.index' is not a valid view In template /var/www/html/django_app/polls/templates/polls/detail.html, error at line 5 Reverse for 'polls.index' not found. 'polls.index' is not a valid view function or pattern name... I have looked up and researched this question on here for a while and am hitting a wall. There are many references to the problem but none that

Django cannot login (login view does not return set-cookie header for sessionid at login)

半城伤御伤魂 提交于 2021-01-29 19:34:18
问题 I am getting the following response from the Django (2.2) default login view: Request URL: https://api.n.exchange/en/accounts/login/?next=/en/referrals/ Request Method: GET Status Code: 200 OK Remote Address: 104.25.23.99:443 Referrer Policy: no-referrer-when-downgrade Cache-Control: max-age=0, no-cache, no-store, must-revalidate CF-RAY: 51105b439e71b50e-VNO Connection: keep-alive Content-Encoding: br Content-Language: en Content-Type: text/html; charset=utf-8 Date: Wed, 04 Sep 2019 13:37:09

Object of type 'bytes' is not JSON serializable in python3

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-28 07:12:36
问题 My Code is configfile = open("abc.txt",'rb').read() return base64.b64encode(configfile) got error "Object of type 'bytes' is not JSON serializable in python3.6" on ec2 回答1: Above issue appeared when i updated Django 1.8 to Django 2.2.6 I solve this by Consider installing and using [simplejson][1], which can handle bytes strings in addition to unicode, to install it use command below: pip3 install simplejson Usage in code: import simplejson as json json.dumps({b'name': b'dev'}) This will solve

NoReverseMatch at /account/login/

試著忘記壹切 提交于 2021-01-07 03:08:58
问题 I'm trying to figure out Django default auth and when I log in with correct credentials it give me this error NoReverseMatch at /account/login/ Reverse for 'dashboard' not found. 'dashboard' is not a valid view function or pattern name. Request Method: POST Request URL: http://127.0.0.1:8000/account/login/ Django Version: 2.2 Exception Type: NoReverseMatch Exception Value: Reverse for 'dashboard' not found. 'dashboard' is not a valid view function or pattern name. Exception Location: C:\Users

Using SQLite3 with Django 2.2 and Python 3.6.7 on Centos7

微笑、不失礼 提交于 2020-05-25 04:13:51
问题 I am moving my Django code from 2.1.7 directly to the new Django 2.2. The only problem I encountered in my Centos7 development environment was that my local development database (sqlite3) version was incompatible using my Python 3.6.7. The error I was getting from "manage.py runserver" was: django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later I am unable to use another version of Python because this is the maximum supported by AWS elasticbeanstalk. The Python 3.6.7 seems to come

“No installed app with label 'admin'” in empty Django 2.2 project

邮差的信 提交于 2020-01-12 19:16:40
问题 I am starting a new project in Django 2.2 using the same commands as I always do: python3 -m venv django-env . django-env/bin/activate pip install django django-admin startproject mysite cd mysite/ python3 manage.py runserver 8080 This should result in a running Django site, ready to write some code. Unfortunately, now I'm getting a strange error: LookupError: No installed app with label 'admin'. Full traceback: Watching for file changes with StatReloader Exception in thread Thread-1:

Why executing form.is_valid() cause deleting of the instance fields that aren't in the form in django?

一笑奈何 提交于 2020-01-07 09:24:03
问题 Suppose this view that is for edit record: def edit_post(request, slug): post = get_object_or_404(Post, slug=slug) if request.method == "POST": form = AddPostForm(request.POST, request.FILES, instance=post) # 1 if form.is_valid(): # 2 new_post = form.save(commit=False) new_post.save() return redirect('administrator:view_admin_post') ... Now assume these: I have field1 that is exist in POST model. field1 has default value and suppose that the current value of field1 depends on previous. Also

Django: put offline a post after an event

試著忘記壹切 提交于 2019-12-31 04:13:21
问题 I'm trying to put offline the posts after an event, a definite date. I've developed a simple model for test my aim and inside the model I've put a function( named is_expired ) that, ideally, must define if a post is or not is online. Below there is the model : from django.db import models from django.utils import timezone import datetime class BlogPost(models.Model): CHOICHES = ( ("Unselected", "Unselected"), ("One Month", "One Month"), ("One Year", "One Year"), ) title = models.CharField(