This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db import models | |
| from django.contrib.postgres.indexes import BrinIndex | |
| class Account(models.Model): | |
| id = models.AutoField() | |
| username = models.CharField(max_lenght=100) | |
| password = models.CharField(max_lenght=200) | |
| class Meta: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| from django.utils import timezone | |
| now_time = timezone.now().timetuple() | |
| formatted_time = time.strftime("%d-%m-%Y %H:%M:%S", now_time) | |
| print(formatted_time) # it will print '15-12-2019 10:49:54' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from xml.etree.ElementTree import fromstring | |
| from xmljson import parker | |
| xml_data = | |
| <?xml version="1.0"?> | |
| <COMMAND> | |
| <ID>2341</ID> | |
| <NAME>"testname"</NAME> | |
| <EMAIL>"testemail@gmail.com"</EMAIL> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data = { | |
| "id": "124324", | |
| "name": "testname", | |
| "email": "testname@gmail.com", | |
| "password": "test1234" | |
| } | |
| def get_json_to_xml_data(data): | |
| return f''' | |
| <?xml version="1.0"?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def authentication_decorator(function): | |
| def wrap(request, *args, **kwargs): | |
| user_token = request.META.get('HTTP_AUTHORIZATION') | |
| user_response, status_code = backend_obj.get_user(user_token) | |
| if status_code == 200: | |
| kwargs = user_response | |
| return function(request, *args, **kwargs) | |
| return wrap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # should not use | |
| try: | |
| Account.objects.get(username='testuser', password='test1234') | |
| except ObjectDoesNotExist: | |
| Account.objects.create(username='testuser', password='test1234') | |
| # should use | |
| try: | |
| Account.objects.get_or_create(username='testuser', password='test1234') | |
| except Exception as e: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -> sudo su - postgres # To perform administrative tasks | |
| -> password # Enter user password | |
| -> psql # Log into a Postgres session | |
| -> CREATE DATABASE db_name; | |
| -> CREATE USER db_user WITH PASSWORD 'your_password'; | |
| -> ALTER ROLE db_user SET client_encoding TO 'utf8'; | |
| -> ALTER ROLE db_user SET default_transaction_isolation TO 'read committed'; | |
| -> ALTER ROLE db_user SET timezone TO 'UTC'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db import connections, OperationalError | |
| # Drop all tables from a given database | |
| """ | |
| python manage.py runscript clean_database_tables | |
| """ | |
| def run(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| TEMPLATES = [ | |
| { | |
| 'BACKEND': 'django.template.backends.django.DjangoTemplates', | |
| 'DIRS': [os.path.join(BASE_DIR, 'templates')], | |
| 'APP_DIRS': True, | |
| 'OPTIONS': { | |
| 'context_processors': [ | |
| 'django.template.context_processors.debug', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML> | |
| <html> | |
| <head> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <style> | |
| p { | |
| text-align: center; | |
| font-size: 60px; | |
| margin-top: 0px; | |
| } |
OlderNewer