Kim Majali wrote on 13/11/2023
# reCAPTCHA
GOOGLE_RECAPTCHA_SITE_KEY = '6LfHCw0pAAasddasdasd'
GOOGLE_RECAPTCHA_SECRET_KEY = '6LfHCw0pasdasdasdasdas'
pip install requests
We choose lib.py to create our reusable function
from django.conf import settings
import requests
def validate_recaptcha(request):
''' reCAPTCHA validation '''
recaptcha_response = request.POST.get('g-recaptcha-response')
data = {
'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY,
'response': recaptcha_response
}
r = requests.post('https://www.google.com/recaptcha/api/siteverify', data=data)
result = r.json()
return result
from .lib import validate_recaptcha
def my_view(request):
if request.method == 'POST':
# do your form validation
if validate_recaptcha(request):
#Save
else:
print('wrong recaptcha')
Read moreKim Majali wrote on 08/06/2022
class CompanyCurreny(models.Model):
company = models.ForeignKey(Company, on_delete=models.CASCADE)
currency = models.ForeignKey(Currency, on_delete=models.CASCADE)
class Meta:
unique_together = ('company', 'currency',)
def __str__(self):
return str(self.currency)
Read moreKim Majali wrote on 08/06/2022
Kim Majali wrote on 08/06/2022
class MyModel(models.Model):
# file will be uploaded to MEDIA_ROOT/uploads
upload = models.FileField(upload_to='uploads/')
Read moreKim Majali wrote on 08/06/2022
Topics: IntegrationsModels