From 0bcd890e29c2d39d16849729c713c4f0979f5ced Mon Sep 17 00:00:00 2001 From: Huthman King Date: Tue, 4 Dec 2018 13:10:33 -0500 Subject: [PATCH 01/46] added pipfiles --- Pipfile | 12 ++++++++++++ Pipfile.lock | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 Pipfile create mode 100644 Pipfile.lock diff --git a/Pipfile b/Pipfile new file mode 100644 index 000000000..8a20dc9f0 --- /dev/null +++ b/Pipfile @@ -0,0 +1,12 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +django = "*" + +[dev-packages] + +[requires] +python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 000000000..76307f4d0 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,36 @@ +{ + "_meta": { + "hash": { + "sha256": "627ef89f247ecee27e9ef0dabe116108d09c47abf171c900a8817befa64f9dd2" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "django": { + "hashes": [ + "sha256:068d51054083d06ceb32ce02b7203f1854256047a0d58682677dd4f81bceabd7", + "sha256:55409a056b27e6d1246f19ede41c6c610e4cab549c005b62cbeefabc6433356b" + ], + "index": "pypi", + "version": "==2.1.4" + }, + "pytz": { + "hashes": [ + "sha256:31cb35c89bd7d333cd32c5f278fca91b523b0834369e757f4c5641ea252236ca", + "sha256:8e0f8568c118d3077b46be7d654cc8167fa916092e28320cde048e54bfc9f1e6" + ], + "version": "==2018.7" + } + }, + "develop": {} +} From 737d6d22840c0629d48b8e8ac3ba3437599eafbc Mon Sep 17 00:00:00 2001 From: Huthman King Date: Tue, 4 Dec 2018 13:59:51 -0500 Subject: [PATCH 02/46] Day 1 -halfway Created project and app Added notes class Added initial migration --- .vscode/settings.json | 3 + Pipfile | 1 + Pipfile.lock | 9 ++- djorg/__init__.py | 0 djorg/settings.py | 121 +++++++++++++++++++++++++++++++ djorg/urls.py | 21 ++++++ djorg/wsgi.py | 16 ++++ manage.py | 15 ++++ notes/__init__.py | 0 notes/admin.py | 3 + notes/apps.py | 5 ++ notes/migrations/0001_initial.py | 23 ++++++ notes/migrations/__init__.py | 0 notes/models.py | 8 ++ notes/tests.py | 3 + notes/views.py | 3 + 16 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 djorg/__init__.py create mode 100644 djorg/settings.py create mode 100644 djorg/urls.py create mode 100644 djorg/wsgi.py create mode 100755 manage.py create mode 100644 notes/__init__.py create mode 100644 notes/admin.py create mode 100644 notes/apps.py create mode 100644 notes/migrations/0001_initial.py create mode 100644 notes/migrations/__init__.py create mode 100644 notes/models.py create mode 100644 notes/tests.py create mode 100644 notes/views.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..9cba53205 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/Users/Huff/.local/share/virtualenvs/Intro-Django-N-_rix2Y/bin/python" +} \ No newline at end of file diff --git a/Pipfile b/Pipfile index 8a20dc9f0..172da92c2 100644 --- a/Pipfile +++ b/Pipfile @@ -5,6 +5,7 @@ name = "pypi" [packages] django = "*" +python-decouple = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 76307f4d0..666b71ab8 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "627ef89f247ecee27e9ef0dabe116108d09c47abf171c900a8817befa64f9dd2" + "sha256": "0bb3b331760d823d01166b55e53cd9c02ded57f108f27a6e4dd739e3ed291a1f" }, "pipfile-spec": 6, "requires": { @@ -24,6 +24,13 @@ "index": "pypi", "version": "==2.1.4" }, + "python-decouple": { + "hashes": [ + "sha256:1317df14b43efee4337a4aa02914bf004f010cd56d6c4bd894e6474ec8c4fe2d" + ], + "index": "pypi", + "version": "==3.1" + }, "pytz": { "hashes": [ "sha256:31cb35c89bd7d333cd32c5f278fca91b523b0834369e757f4c5641ea252236ca", diff --git a/djorg/__init__.py b/djorg/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/djorg/settings.py b/djorg/settings.py new file mode 100644 index 000000000..abe564263 --- /dev/null +++ b/djorg/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for djorg project. + +Generated by 'django-admin startproject' using Django 2.1.4. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.1/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'm#-$(a!u!2+5yhu&w8pz_uk-c8n=6mc-vxjvv-x*9e-)&ulyg&' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'notes', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'djorg.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'djorg.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.1/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.1/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/djorg/urls.py b/djorg/urls.py new file mode 100644 index 000000000..f4f667215 --- /dev/null +++ b/djorg/urls.py @@ -0,0 +1,21 @@ +"""djorg URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/djorg/wsgi.py b/djorg/wsgi.py new file mode 100644 index 000000000..7bb827bb0 --- /dev/null +++ b/djorg/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for djorg project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djorg.settings') + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 000000000..ae1e94bc6 --- /dev/null +++ b/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djorg.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/notes/__init__.py b/notes/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/notes/admin.py b/notes/admin.py new file mode 100644 index 000000000..8c38f3f3d --- /dev/null +++ b/notes/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/notes/apps.py b/notes/apps.py new file mode 100644 index 000000000..b6155aca3 --- /dev/null +++ b/notes/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class NotesConfig(AppConfig): + name = 'notes' diff --git a/notes/migrations/0001_initial.py b/notes/migrations/0001_initial.py new file mode 100644 index 000000000..4b1cef154 --- /dev/null +++ b/notes/migrations/0001_initial.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1.4 on 2018-12-04 18:19 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Note', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('title', models.CharField(max_length=200)), + ('content', models.TextField(blank=True)), + ], + ), + ] diff --git a/notes/migrations/__init__.py b/notes/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/notes/models.py b/notes/models.py new file mode 100644 index 000000000..c5dc53c73 --- /dev/null +++ b/notes/models.py @@ -0,0 +1,8 @@ +from django.db import models +from uuid import uuid4 + +# Create your models here. +class Note(models.Model): + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) + title = models.CharField(max_length=200) + content = models.TextField(blank=True) \ No newline at end of file diff --git a/notes/tests.py b/notes/tests.py new file mode 100644 index 000000000..7ce503c2d --- /dev/null +++ b/notes/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/notes/views.py b/notes/views.py new file mode 100644 index 000000000..91ea44a21 --- /dev/null +++ b/notes/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From 2299a2c6503f69e58fbbb74f7ac673134d27a9eb Mon Sep 17 00:00:00 2001 From: Huthman King Date: Tue, 4 Dec 2018 14:14:33 -0500 Subject: [PATCH 03/46] Decouple added .env and updated secret key updated debug --- djorg/settings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/djorg/settings.py b/djorg/settings.py index abe564263..8e3588899 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -11,6 +11,7 @@ """ import os +from decouple import config # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -20,10 +21,10 @@ # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'm#-$(a!u!2+5yhu&w8pz_uk-c8n=6mc-vxjvv-x*9e-)&ulyg&' +SECRET_KEY = config('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = config('DEBUG', cast=bool) ALLOWED_HOSTS = [] From 46712939f4b2129b78a87a99f8063c616314e9a6 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Tue, 4 Dec 2018 19:45:28 -0500 Subject: [PATCH 04/46] Added Admin User able to login able to add note and edit note --- notes/admin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/notes/admin.py b/notes/admin.py index 8c38f3f3d..333f7f50e 100644 --- a/notes/admin.py +++ b/notes/admin.py @@ -1,3 +1,6 @@ from django.contrib import admin +from .models import Note + +admin.site.register(Note) # Register your models here. From a849ad9082d1be66a4d27caa32c1b4795621f2e6 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Tue, 4 Dec 2018 19:59:06 -0500 Subject: [PATCH 05/46] Migration w/ New Fields Now tracking created and modified dates --- notes/admin.py | 7 +++++- notes/migrations/0002_auto_20181205_0051.py | 25 +++++++++++++++++++++ notes/models.py | 5 ++++- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 notes/migrations/0002_auto_20181205_0051.py diff --git a/notes/admin.py b/notes/admin.py index 333f7f50e..4c2f7c8d6 100644 --- a/notes/admin.py +++ b/notes/admin.py @@ -1,6 +1,11 @@ from django.contrib import admin from .models import Note -admin.site.register(Note) + + # Register your models here. +class NoteAdmin(admin.ModelAdmin): + readonly_fields=('created_at', 'last_modified') + +admin.site.register(Note, NoteAdmin) \ No newline at end of file diff --git a/notes/migrations/0002_auto_20181205_0051.py b/notes/migrations/0002_auto_20181205_0051.py new file mode 100644 index 000000000..89ba2c4c7 --- /dev/null +++ b/notes/migrations/0002_auto_20181205_0051.py @@ -0,0 +1,25 @@ +# Generated by Django 2.1.4 on 2018-12-05 00:51 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('notes', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='note', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='note', + name='last_modified', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/notes/models.py b/notes/models.py index c5dc53c73..0e0f902e7 100644 --- a/notes/models.py +++ b/notes/models.py @@ -5,4 +5,7 @@ class Note(models.Model): id = models.UUIDField(primary_key=True, default=uuid4, editable=False) title = models.CharField(max_length=200) - content = models.TextField(blank=True) \ No newline at end of file + content = models.TextField(blank=True) + created_at = models.DateTimeField(auto_now_add=True) + last_modified = models.DateTimeField(auto_now=True) + From 6dcd5b1a5d46d0e0d79180489cd3289f82f86747 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Tue, 4 Dec 2018 20:06:05 -0500 Subject: [PATCH 06/46] Added personal notes migration --- notes/admin.py | 3 ++- notes/migrations/0003_personalnote.py | 24 ++++++++++++++++++++++++ notes/models.py | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 notes/migrations/0003_personalnote.py diff --git a/notes/admin.py b/notes/admin.py index 4c2f7c8d6..d00432a02 100644 --- a/notes/admin.py +++ b/notes/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin from .models import Note +from .models import PersonalNote @@ -8,4 +9,4 @@ class NoteAdmin(admin.ModelAdmin): readonly_fields=('created_at', 'last_modified') -admin.site.register(Note, NoteAdmin) \ No newline at end of file +admin.site.register(Note, NoteAdmin, PersonalNote) \ No newline at end of file diff --git a/notes/migrations/0003_personalnote.py b/notes/migrations/0003_personalnote.py new file mode 100644 index 000000000..76507d3cd --- /dev/null +++ b/notes/migrations/0003_personalnote.py @@ -0,0 +1,24 @@ +# Generated by Django 2.1.4 on 2018-12-05 01:03 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('notes', '0002_auto_20181205_0051'), + ] + + operations = [ + migrations.CreateModel( + name='PersonalNote', + fields=[ + ('note_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='notes.Note')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + bases=('notes.note',), + ), + ] diff --git a/notes/models.py b/notes/models.py index 0e0f902e7..9f7fdc9e0 100644 --- a/notes/models.py +++ b/notes/models.py @@ -1,5 +1,6 @@ from django.db import models from uuid import uuid4 +from django.contrib.auth.models import User # Create your models here. class Note(models.Model): @@ -9,3 +10,5 @@ class Note(models.Model): created_at = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True) +class PersonalNote(Note): + user = models.ForeignKey(User, on_delete=models.CASCADE) \ No newline at end of file From ea7ef2e4c7610eb63d4e57e732865490e3bdd0a8 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Tue, 4 Dec 2018 20:14:52 -0500 Subject: [PATCH 07/46] User/PersonalNote Class Able to add user and create personal note under user --- notes/admin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/notes/admin.py b/notes/admin.py index d00432a02..3cd144ff7 100644 --- a/notes/admin.py +++ b/notes/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Note -from .models import PersonalNote +from .models import Note, PersonalNote + @@ -9,4 +9,5 @@ class NoteAdmin(admin.ModelAdmin): readonly_fields=('created_at', 'last_modified') -admin.site.register(Note, NoteAdmin, PersonalNote) \ No newline at end of file +admin.site.register(Note, NoteAdmin) +admin.site.register(PersonalNote) \ No newline at end of file From ed8fe7e2afe1e4f6389f186a30c81d9cc22bbb3d Mon Sep 17 00:00:00 2001 From: Huthman King Date: Wed, 5 Dec 2018 15:24:53 -0500 Subject: [PATCH 08/46] Installed the REST Framework --- Pipfile | 1 + Pipfile.lock | 10 +++++++++- djorg/settings.py | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Pipfile b/Pipfile index 172da92c2..2d6b93ec0 100644 --- a/Pipfile +++ b/Pipfile @@ -6,6 +6,7 @@ name = "pypi" [packages] django = "*" python-decouple = "*" +djangorestframework = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 666b71ab8..74432aa3b 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "0bb3b331760d823d01166b55e53cd9c02ded57f108f27a6e4dd739e3ed291a1f" + "sha256": "f60c55d31de62ba3f850d6c16dc83ccc1a0d6fe44e337b58447a45133fdc5bb9" }, "pipfile-spec": 6, "requires": { @@ -24,6 +24,14 @@ "index": "pypi", "version": "==2.1.4" }, + "djangorestframework": { + "hashes": [ + "sha256:607865b0bb1598b153793892101d881466bd5a991de12bd6229abb18b1c86136", + "sha256:63f76cbe1e7d12b94c357d7e54401103b2e52aef0f7c1650d6c820ad708776e5" + ], + "index": "pypi", + "version": "==3.9.0" + }, "python-decouple": { "hashes": [ "sha256:1317df14b43efee4337a4aa02914bf004f010cd56d6c4bd894e6474ec8c4fe2d" diff --git a/djorg/settings.py b/djorg/settings.py index 8e3588899..fc085ec11 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -39,6 +39,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'rest_framework', ] MIDDLEWARE = [ @@ -71,6 +72,12 @@ WSGI_APPLICATION = 'djorg.wsgi.application' +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly', + ] +} + # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases From bbc1b979f1f6c4fe9574db2e63ff8e2b7f11bc8f Mon Sep 17 00:00:00 2001 From: Huthman King Date: Wed, 5 Dec 2018 16:29:36 -0500 Subject: [PATCH 09/46] Exposed the PersonalNotes Model --- notes/api.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 notes/api.py diff --git a/notes/api.py b/notes/api.py new file mode 100644 index 000000000..fbc8d234d --- /dev/null +++ b/notes/api.py @@ -0,0 +1,10 @@ +from rest_framework import serializers, viewsets + +class PersonalNoteSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = PersonalNote + fields = ('title', 'content') + +class PersonalNoteViewSet(viewsets.ModelViewSet): + serializer_class = PersonalNoteSerializer + queryset = PersonalNote.objects.all() \ No newline at end of file From c2afc3bec8675514140aae922ca7a4901d59ca5c Mon Sep 17 00:00:00 2001 From: Huthman King Date: Wed, 5 Dec 2018 16:37:06 -0500 Subject: [PATCH 10/46] Added Routes --- djorg/urls.py | 8 +++++++- notes/api.py | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/djorg/urls.py b/djorg/urls.py index f4f667215..dfaaadddf 100644 --- a/djorg/urls.py +++ b/djorg/urls.py @@ -14,8 +14,14 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include +from rest_framework import routers +from notes.api import PersonalNoteViewSet + +router = routers.DefaultRouter() +router.register(r'notes', PersonalNoteViewSet) urlpatterns = [ path('admin/', admin.site.urls), + path('api/', include(router.urls)), ] diff --git a/notes/api.py b/notes/api.py index fbc8d234d..6e47acee8 100644 --- a/notes/api.py +++ b/notes/api.py @@ -1,4 +1,5 @@ from rest_framework import serializers, viewsets +from .models import PersonalNote class PersonalNoteSerializer(serializers.HyperlinkedModelSerializer): class Meta: From 45be69ea9cc55cad523e3ab58f5b3f87c01c2f48 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Wed, 5 Dec 2018 17:04:00 -0500 Subject: [PATCH 11/46] Added the Required user Field --- notes/api.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/notes/api.py b/notes/api.py index 6e47acee8..bc9c06408 100644 --- a/notes/api.py +++ b/notes/api.py @@ -2,9 +2,15 @@ from .models import PersonalNote class PersonalNoteSerializer(serializers.HyperlinkedModelSerializer): - class Meta: - model = PersonalNote - fields = ('title', 'content') + class Meta: + model = PersonalNote + fields = ('title', 'content') + def create(self, validated_data): + user = self.context['request'].user + note = PersonalNote.objects.create(user=user, **validated_data) + return note + + class PersonalNoteViewSet(viewsets.ModelViewSet): serializer_class = PersonalNoteSerializer From 1456af331e4e0b540c98018b914e7cbc42c215d0 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Wed, 5 Dec 2018 17:13:53 -0500 Subject: [PATCH 12/46] Filter Results by User --- notes/api.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/notes/api.py b/notes/api.py index bc9c06408..ff337880a 100644 --- a/notes/api.py +++ b/notes/api.py @@ -1,5 +1,5 @@ from rest_framework import serializers, viewsets -from .models import PersonalNote +from .models import PersonalNote, Note class PersonalNoteSerializer(serializers.HyperlinkedModelSerializer): class Meta: @@ -14,4 +14,11 @@ def create(self, validated_data): class PersonalNoteViewSet(viewsets.ModelViewSet): serializer_class = PersonalNoteSerializer - queryset = PersonalNote.objects.all() \ No newline at end of file + queryset = Note.objects.none() + def get_queryset(self): + user = self.request.user + + if user.is_anonymous: + return PersonalNote.objects.none() + else: + return PersonalNote.objects.filter(user=user) \ No newline at end of file From 658d33ce41b4f24f84df33359a1ee00ccf6a55d1 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Wed, 5 Dec 2018 17:19:01 -0500 Subject: [PATCH 13/46] Set up Cors --- djorg/settings.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/djorg/settings.py b/djorg/settings.py index fc085ec11..35e4b8d98 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -40,9 +40,11 @@ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', + 'corsheaders', ] MIDDLEWARE = [ + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -52,6 +54,8 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] +CORS_ORIGIN_ALLOW_ALL = True + ROOT_URLCONF = 'djorg.urls' TEMPLATES = [ From 4407d560593f141fb7b7f04e7baacb7a99307408 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Wed, 5 Dec 2018 17:24:36 -0500 Subject: [PATCH 14/46] Set up Token Authentication --- djorg/settings.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/djorg/settings.py b/djorg/settings.py index 35e4b8d98..6d1d196e0 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -41,6 +41,7 @@ 'django.contrib.staticfiles', 'rest_framework', 'corsheaders', + 'rest_framework.authtoken', ] MIDDLEWARE = [ @@ -79,7 +80,12 @@ REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly', - ] + ], + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.BasicAuthentication', + 'rest_framework.authentication.SessionAuthentication', + 'rest_framework.authentication.TokenAuthentication', + ), } From d127cf57b99b1d9a309b930b830e03043c8572d9 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Wed, 5 Dec 2018 17:33:21 -0500 Subject: [PATCH 15/46] Day 4 Set up Token Authentication Set up the ROute Test the Endpoint Completed --- djorg/urls.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/djorg/urls.py b/djorg/urls.py index dfaaadddf..2d2e4c34c 100644 --- a/djorg/urls.py +++ b/djorg/urls.py @@ -14,8 +14,9 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path, include +from django.urls import path, include, re_path from rest_framework import routers +from rest_framework.authtoken import views from notes.api import PersonalNoteViewSet router = routers.DefaultRouter() @@ -24,4 +25,5 @@ urlpatterns = [ path('admin/', admin.site.urls), path('api/', include(router.urls)), + re_path(r'^api-token-auth/', views.obtain_auth_token), ] From 2b6ab1073b284266384b9bb17757138722501e34 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Wed, 5 Dec 2018 17:35:49 -0500 Subject: [PATCH 16/46] Added info to .env --- djorg/urls.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/djorg/urls.py b/djorg/urls.py index 2d2e4c34c..027d0419a 100644 --- a/djorg/urls.py +++ b/djorg/urls.py @@ -27,3 +27,6 @@ path('api/', include(router.urls)), re_path(r'^api-token-auth/', views.obtain_auth_token), ] + + + From 0c13820cb9d5de1d08111e7428d5c5263d71c197 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Thu, 6 Dec 2018 19:10:53 -0500 Subject: [PATCH 17/46] Added Desirable Quotes was a new app created User can add quote and name of author --- djorg/settings.py | 1 + djorg/urls.py | 2 ++ quotes/__init__.py | 0 quotes/admin.py | 13 +++++++++++ quotes/api.py | 24 +++++++++++++++++++++ quotes/apps.py | 5 +++++ quotes/migrations/0001_initial.py | 36 +++++++++++++++++++++++++++++++ quotes/migrations/__init__.py | 0 quotes/models.py | 14 ++++++++++++ quotes/tests.py | 3 +++ quotes/views.py | 3 +++ 11 files changed, 101 insertions(+) create mode 100644 quotes/__init__.py create mode 100644 quotes/admin.py create mode 100644 quotes/api.py create mode 100644 quotes/apps.py create mode 100644 quotes/migrations/0001_initial.py create mode 100644 quotes/migrations/__init__.py create mode 100644 quotes/models.py create mode 100644 quotes/tests.py create mode 100644 quotes/views.py diff --git a/djorg/settings.py b/djorg/settings.py index 6d1d196e0..ad77b0c82 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -33,6 +33,7 @@ INSTALLED_APPS = [ 'notes', + 'quotes', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/djorg/urls.py b/djorg/urls.py index 027d0419a..b2ffaf2a7 100644 --- a/djorg/urls.py +++ b/djorg/urls.py @@ -18,9 +18,11 @@ from rest_framework import routers from rest_framework.authtoken import views from notes.api import PersonalNoteViewSet +from quotes.api import PersonalQuoteViewSet router = routers.DefaultRouter() router.register(r'notes', PersonalNoteViewSet) +router.register(r'quotes', PersonalQuoteViewSet) urlpatterns = [ path('admin/', admin.site.urls), diff --git a/quotes/__init__.py b/quotes/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/quotes/admin.py b/quotes/admin.py new file mode 100644 index 000000000..96982425e --- /dev/null +++ b/quotes/admin.py @@ -0,0 +1,13 @@ +from django.contrib import admin +from .models import Quote, PersonalQuote + + + + + +# Register your models here. +class QuoteAdmin(admin.ModelAdmin): + readonly_fields=('created_at', 'last_modified') + +admin.site.register(Quote, QuoteAdmin) +admin.site.register(PersonalQuote) \ No newline at end of file diff --git a/quotes/api.py b/quotes/api.py new file mode 100644 index 000000000..1b584e038 --- /dev/null +++ b/quotes/api.py @@ -0,0 +1,24 @@ +from rest_framework import serializers, viewsets +from .models import PersonalQuote, Quote + +class PersonalQuoteSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = PersonalQuote + fields = ('Author', 'Quote') + def create(self, validated_data): + user = self.context['request'].user + note = PersonalQuote.objects.create(user=user, **validated_data) + return Quote + + + +class PersonalQuoteViewSet(viewsets.ModelViewSet): + serializer_class = PersonalQuoteSerializer + queryset = Quote.objects.none() + def get_queryset(self): + user = self.request.user + + if user.is_anonymous: + return PersonalQuote.objects.none() + else: + return PersonalQuote.objects.filter(user=user) \ No newline at end of file diff --git a/quotes/apps.py b/quotes/apps.py new file mode 100644 index 000000000..1ca6df11b --- /dev/null +++ b/quotes/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class QuotesConfig(AppConfig): + name = 'quotes' diff --git a/quotes/migrations/0001_initial.py b/quotes/migrations/0001_initial.py new file mode 100644 index 000000000..c45472365 --- /dev/null +++ b/quotes/migrations/0001_initial.py @@ -0,0 +1,36 @@ +# Generated by Django 2.1.4 on 2018-12-07 00:01 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Quote', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('Author', models.CharField(max_length=200)), + ('Quote', models.TextField(blank=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('last_modified', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='PersonalQuote', + fields=[ + ('quote_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='quotes.Quote')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + bases=('quotes.quote',), + ), + ] diff --git a/quotes/migrations/__init__.py b/quotes/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/quotes/models.py b/quotes/models.py new file mode 100644 index 000000000..e2b0b7fd8 --- /dev/null +++ b/quotes/models.py @@ -0,0 +1,14 @@ +from django.db import models +from uuid import uuid4 +from django.contrib.auth.models import User + +# Create your models here. +class Quote(models.Model): + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) + Author = models.CharField(max_length=200) + Quote = models.TextField(blank=True) + created_at = models.DateTimeField(auto_now_add=True) + last_modified = models.DateTimeField(auto_now=True) + +class PersonalQuote(Quote): + user = models.ForeignKey(User, on_delete=models.CASCADE) \ No newline at end of file diff --git a/quotes/tests.py b/quotes/tests.py new file mode 100644 index 000000000..7ce503c2d --- /dev/null +++ b/quotes/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/quotes/views.py b/quotes/views.py new file mode 100644 index 000000000..91ea44a21 --- /dev/null +++ b/quotes/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From acf59d695b719acec5a08ae07d2245a64c444d0c Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 12:40:05 -0500 Subject: [PATCH 18/46] Heroku Completed the steps to deploy heroku Attempt 1 --- Pipfile | 4 ++ Pipfile.lock | 62 +++++++++++++++++++- Procfile | 1 + djorg/settings.py | 6 +- quotes/api.py | 4 +- quotes/migrations/0002_auto_20181207_0027.py | 23 ++++++++ quotes/models.py | 4 +- 7 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 Procfile create mode 100644 quotes/migrations/0002_auto_20181207_0027.py diff --git a/Pipfile b/Pipfile index 2d6b93ec0..190afb452 100644 --- a/Pipfile +++ b/Pipfile @@ -7,6 +7,10 @@ name = "pypi" django = "*" python-decouple = "*" djangorestframework = "*" +gunicorn = "*" +"psycopg2-binary" = "*" +dj-database-url = "*" +whitenoise = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 74432aa3b..9389d5bec 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "f60c55d31de62ba3f850d6c16dc83ccc1a0d6fe44e337b58447a45133fdc5bb9" + "sha256": "8afcbb900798e3365aaa12966ff1c4a545134cbc204818e57f81d4504337595e" }, "pipfile-spec": 6, "requires": { @@ -16,6 +16,14 @@ ] }, "default": { + "dj-database-url": { + "hashes": [ + "sha256:4aeaeb1f573c74835b0686a2b46b85990571159ffc21aa57ecd4d1e1cb334163", + "sha256:851785365761ebe4994a921b433062309eb882fedd318e1b0fcecc607ed02da9" + ], + "index": "pypi", + "version": "==0.5.0" + }, "django": { "hashes": [ "sha256:068d51054083d06ceb32ce02b7203f1854256047a0d58682677dd4f81bceabd7", @@ -32,6 +40,50 @@ "index": "pypi", "version": "==3.9.0" }, + "gunicorn": { + "hashes": [ + "sha256:aa8e0b40b4157b36a5df5e599f45c9c76d6af43845ba3b3b0efe2c70473c2471", + "sha256:fa2662097c66f920f53f70621c6c58ca4a3c4d3434205e608e121b5b3b71f4f3" + ], + "index": "pypi", + "version": "==19.9.0" + }, + "psycopg2-binary": { + "hashes": [ + "sha256:036bcb198a7cc4ce0fe43344f8c2c9a8155aefa411633f426c8c6ed58a6c0426", + "sha256:1d770fcc02cdf628aebac7404d56b28a7e9ebec8cfc0e63260bd54d6edfa16d4", + "sha256:1fdc6f369dcf229de6c873522d54336af598b9470ccd5300e2f58ee506f5ca13", + "sha256:21f9ddc0ff6e07f7d7b6b484eb9da2c03bc9931dd13e36796b111d631f7135a3", + "sha256:247873cda726f7956f745a3e03158b00de79c4abea8776dc2f611d5ba368d72d", + "sha256:3aa31c42f29f1da6f4fd41433ad15052d5ff045f2214002e027a321f79d64e2c", + "sha256:475f694f87dbc619010b26de7d0fc575a4accf503f2200885cc21f526bffe2ad", + "sha256:4b5e332a24bf6e2fda1f51ca2a57ae1083352293a08eeea1fa1112dc7dd542d1", + "sha256:570d521660574aca40be7b4d532dfb6f156aad7b16b5ed62d1534f64f1ef72d8", + "sha256:59072de7def0690dd13112d2bdb453e20570a97297070f876fbbb7cbc1c26b05", + "sha256:5f0b658989e918ef187f8a08db0420528126f2c7da182a7b9f8bf7f85144d4e4", + "sha256:649199c84a966917d86cdc2046e03d536763576c0b2a756059ae0b3a9656bc20", + "sha256:6645fc9b4705ae8fbf1ef7674f416f89ae1559deec810f6dd15197dfa52893da", + "sha256:6872dd54d4e398d781efe8fe2e2d7eafe4450d61b5c4898aced7610109a6df75", + "sha256:6ce34fbc251fc0d691c8d131250ba6f42fd2b28ef28558d528ba8c558cb28804", + "sha256:73920d167a0a4d1006f5f3b9a3efce6f0e5e883a99599d38206d43f27697df00", + "sha256:8a671732b87ae423e34b51139628123bc0306c2cb85c226e71b28d3d57d7e42a", + "sha256:8d517e8fda2efebca27c2018e14c90ed7dc3f04d7098b3da2912e62a1a5585fe", + "sha256:9475a008eb7279e20d400c76471843c321b46acacc7ee3de0b47233a1e3fa2cf", + "sha256:96947b8cd7b3148fb0e6549fcb31258a736595d6f2a599f8cd450e9a80a14781", + "sha256:abf229f24daa93f67ac53e2e17c8798a71a01711eb9fcdd029abba8637164338", + "sha256:b1ab012f276df584beb74f81acb63905762c25803ece647016613c3d6ad4e432", + "sha256:b22b33f6f0071fe57cb4e9158f353c88d41e739a3ec0d76f7b704539e7076427", + "sha256:b3b2d53274858e50ad2ffdd6d97ce1d014e1e530f82ec8b307edd5d4c921badf", + "sha256:bab26a729befc7b9fab9ded1bba9c51b785188b79f8a2796ba03e7e734269e2e", + "sha256:daa1a593629aa49f506eddc9d23dc7f89b35693b90e1fbcd4480182d1203ea90", + "sha256:dd111280ce40e89fd17b19c1269fd1b74a30fce9d44a550840e86edb33924eb8", + "sha256:e0b86084f1e2e78c451994410de756deba206884d6bed68d5a3d7f39ff5fea1d", + "sha256:eb86520753560a7e89639500e2a254bb6f683342af598088cb72c73edcad21e6", + "sha256:ff18c5c40a38d41811c23e2480615425c97ea81fd7e9118b8b899c512d97c737" + ], + "index": "pypi", + "version": "==2.7.6.1" + }, "python-decouple": { "hashes": [ "sha256:1317df14b43efee4337a4aa02914bf004f010cd56d6c4bd894e6474ec8c4fe2d" @@ -45,6 +97,14 @@ "sha256:8e0f8568c118d3077b46be7d654cc8167fa916092e28320cde048e54bfc9f1e6" ], "version": "==2018.7" + }, + "whitenoise": { + "hashes": [ + "sha256:118ab3e5f815d380171b100b05b76de2a07612f422368a201a9ffdeefb2251c1", + "sha256:42133ddd5229eeb6a0c9899496bdbe56c292394bf8666da77deeb27454c0456a" + ], + "index": "pypi", + "version": "==4.1.2" } }, "develop": {} diff --git a/Procfile b/Procfile new file mode 100644 index 000000000..be138390c --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn djorg.wsgi --log-file - \ No newline at end of file diff --git a/djorg/settings.py b/djorg/settings.py index ad77b0c82..162bd8b4d 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -12,6 +12,7 @@ import os from decouple import config +import dj_database_url # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -26,7 +27,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = config('DEBUG', cast=bool) -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['.herokuapp.com'] # Application definition @@ -48,6 +49,7 @@ MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -100,7 +102,6 @@ } } - # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators @@ -138,3 +139,4 @@ # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') diff --git a/quotes/api.py b/quotes/api.py index 1b584e038..4df7ace2e 100644 --- a/quotes/api.py +++ b/quotes/api.py @@ -4,10 +4,10 @@ class PersonalQuoteSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = PersonalQuote - fields = ('Author', 'Quote') + fields = ('author', 'quote') def create(self, validated_data): user = self.context['request'].user - note = PersonalQuote.objects.create(user=user, **validated_data) + quote = PersonalQuote.objects.create(user=user, **validated_data) return Quote diff --git a/quotes/migrations/0002_auto_20181207_0027.py b/quotes/migrations/0002_auto_20181207_0027.py new file mode 100644 index 000000000..c927dfcee --- /dev/null +++ b/quotes/migrations/0002_auto_20181207_0027.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1.4 on 2018-12-07 00:27 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('quotes', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='quote', + old_name='Author', + new_name='author', + ), + migrations.RenameField( + model_name='quote', + old_name='Quote', + new_name='quote', + ), + ] diff --git a/quotes/models.py b/quotes/models.py index e2b0b7fd8..2823e58d8 100644 --- a/quotes/models.py +++ b/quotes/models.py @@ -5,8 +5,8 @@ # Create your models here. class Quote(models.Model): id = models.UUIDField(primary_key=True, default=uuid4, editable=False) - Author = models.CharField(max_length=200) - Quote = models.TextField(blank=True) + author = models.CharField(max_length=200) + quote = models.TextField(blank=True) created_at = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True) From 1897772092d0535b626100a4322c195f3413354b Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 13:06:44 -0500 Subject: [PATCH 19/46] debug --- djorg/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/djorg/settings.py b/djorg/settings.py index 162bd8b4d..f2719d2f1 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -12,7 +12,7 @@ import os from decouple import config -import dj_database_url + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -22,7 +22,7 @@ # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = config('SECRET_KEY') +SECRET_KEY = 'bx8pxy42p4r9h3ysw($hp-j%jlt#w#ir&z^dj^==d(l5r8j&mm' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = config('DEBUG', cast=bool) From ce2f5131d26d2140998d3b71f306a855a3c4f458 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 13:10:36 -0500 Subject: [PATCH 20/46] Debug --- djorg/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djorg/settings.py b/djorg/settings.py index f2719d2f1..eb1f78f39 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -25,7 +25,7 @@ SECRET_KEY = 'bx8pxy42p4r9h3ysw($hp-j%jlt#w#ir&z^dj^==d(l5r8j&mm' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = config('DEBUG', cast=bool) +DEBUG = config(False, cast=bool) ALLOWED_HOSTS = ['.herokuapp.com'] From 039b90cf1419dda2a5b847de9d79bda6730f7432 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 13:12:05 -0500 Subject: [PATCH 21/46] Debug --- djorg/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djorg/settings.py b/djorg/settings.py index eb1f78f39..ec7f0eb18 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -25,7 +25,7 @@ SECRET_KEY = 'bx8pxy42p4r9h3ysw($hp-j%jlt#w#ir&z^dj^==d(l5r8j&mm' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = config(False, cast=bool) +DEBUG = False ALLOWED_HOSTS = ['.herokuapp.com'] From 44b0a5c0c38dcd3370905c25c8ff4c73ef03e696 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 13:18:42 -0500 Subject: [PATCH 22/46] debug --- djorg/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djorg/settings.py b/djorg/settings.py index ec7f0eb18..09cc5dbfd 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -47,9 +47,9 @@ ] MIDDLEWARE = [ - 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', From 0572ac78cf46538a14c4c5036a841603163ed4bb Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 13:22:24 -0500 Subject: [PATCH 23/46] Debug --- djorg/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/djorg/settings.py b/djorg/settings.py index 09cc5dbfd..7c3b2f8b3 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -12,6 +12,7 @@ import os from decouple import config +from decouple import dj_databse_url # Build paths inside the project like this: os.path.join(BASE_DIR, ...) From 90c5f1b759c64f301ef9f9c6ce7296baeb287a27 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 13:29:17 -0500 Subject: [PATCH 24/46] debug --- djorg/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/djorg/settings.py b/djorg/settings.py index 7c3b2f8b3..09cc5dbfd 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -12,7 +12,6 @@ import os from decouple import config -from decouple import dj_databse_url # Build paths inside the project like this: os.path.join(BASE_DIR, ...) From 750e8b1afae5383b33c67805422152c261d6f3ca Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 13:32:38 -0500 Subject: [PATCH 25/46] debug --- Pipfile | 1 + Pipfile.lock | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Pipfile b/Pipfile index 190afb452..6528acefa 100644 --- a/Pipfile +++ b/Pipfile @@ -11,6 +11,7 @@ gunicorn = "*" "psycopg2-binary" = "*" dj-database-url = "*" whitenoise = "*" +django-cors-headers = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 9389d5bec..979af96aa 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "8afcbb900798e3365aaa12966ff1c4a545134cbc204818e57f81d4504337595e" + "sha256": "8125b5bd02cb8f85c9f0329f5ff7548591ce4fb6ffbe9b3cb8cb0952d2f3cff2" }, "pipfile-spec": 6, "requires": { @@ -32,6 +32,14 @@ "index": "pypi", "version": "==2.1.4" }, + "django-cors-headers": { + "hashes": [ + "sha256:5545009c9b233ea7e70da7dbab7cb1c12afa01279895086f98ec243d7eab46fa", + "sha256:c4c2ee97139d18541a1be7d96fe337d1694623816d83f53cb7c00da9b94acae1" + ], + "index": "pypi", + "version": "==2.4.0" + }, "djangorestframework": { "hashes": [ "sha256:607865b0bb1598b153793892101d881466bd5a991de12bd6229abb18b1c86136", From 38fb547dd24974642a8ea0979a189157500f9c72 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 14:12:13 -0500 Subject: [PATCH 26/46] Trying stuff --- djorg/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djorg/settings.py b/djorg/settings.py index 09cc5dbfd..2fb5f6011 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -27,7 +27,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False -ALLOWED_HOSTS = ['.herokuapp.com'] +ALLOWED_HOSTS = ['notes-huthman.herokuapp.com'] # Application definition From f1272c27cb96d51d092e6c5d10b3ffdca7e8b445 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 14:19:30 -0500 Subject: [PATCH 27/46] Trying 2 --- README.md | 3 +++ djorg/settings.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9203be49d..fb5d81e6e 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,6 @@ Fork this repo to use for your projects this week. * Add a Django front end to the data. * Brainstorm a list of 10 additional features users would find useful. * Implement the brainstormed list. + + +just in case 'rest_framework.authentication.TokenAuthentication', \ No newline at end of file diff --git a/djorg/settings.py b/djorg/settings.py index 2fb5f6011..13c48ba00 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -87,7 +87,6 @@ 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', - 'rest_framework.authentication.TokenAuthentication', ), } @@ -102,6 +101,9 @@ } } +db_from_env = dj_database_url.config(conn_max_age=500) +DATABASES['default'].update(db_from_env) + # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators @@ -140,3 +142,4 @@ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' From a9cf56c199f99091435d09e15525b349f8aaf661 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 14:22:40 -0500 Subject: [PATCH 28/46] Debug --- djorg/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/djorg/settings.py b/djorg/settings.py index 13c48ba00..23d75cb47 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -12,6 +12,7 @@ import os from decouple import config +import dj_database_url # Build paths inside the project like this: os.path.join(BASE_DIR, ...) From dff212dbc3eb5cc0bc8c8944a5ce2d2d45b46795 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 14:26:37 -0500 Subject: [PATCH 29/46] Finished --- README.md | 3 --- djorg/settings.py | 7 +++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index fb5d81e6e..9203be49d 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,3 @@ Fork this repo to use for your projects this week. * Add a Django front end to the data. * Brainstorm a list of 10 additional features users would find useful. * Implement the brainstormed list. - - -just in case 'rest_framework.authentication.TokenAuthentication', \ No newline at end of file diff --git a/djorg/settings.py b/djorg/settings.py index 23d75cb47..a13636fbe 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -12,7 +12,7 @@ import os from decouple import config -import dj_database_url + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) @@ -88,6 +88,7 @@ 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', + 'rest_framework.authentication.TokenAuthentication', ), } @@ -102,8 +103,6 @@ } } -db_from_env = dj_database_url.config(conn_max_age=500) -DATABASES['default'].update(db_from_env) # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators @@ -143,4 +142,4 @@ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') -STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' + From a16ed3cb00bb4df07abe9bf8e25b0fcfa8269be9 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 16:53:04 -0500 Subject: [PATCH 30/46] Heroku login --- djorg/settings.py | 5 +++++ requirements.txt | 3 +++ 2 files changed, 8 insertions(+) create mode 100644 requirements.txt diff --git a/djorg/settings.py b/djorg/settings.py index a13636fbe..9f38972ed 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -12,6 +12,7 @@ import os from decouple import config +import dj_database_url @@ -103,6 +104,7 @@ } } +DATABASES['default'] = dj_database_url.config(conn_max_age=600) # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators @@ -143,3 +145,6 @@ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') +if 'DATABASE_URL' in os.environ: + import dj_database_url + DATABASES = {'default': dj_database_url.config()} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..d135b2205 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pip freeze > requirements.txt +dj-database-url +psycopg2 \ No newline at end of file From 36fdbfd21f448736ea5bde97e4bae83bdc4aa4e0 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 17:30:11 -0500 Subject: [PATCH 31/46] Heroku final --- djorg/settings.py | 9 ++------- notes/admin.py | 1 + 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/djorg/settings.py b/djorg/settings.py index 9f38972ed..e0813019b 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -12,7 +12,6 @@ import os from decouple import config -import dj_database_url @@ -89,7 +88,6 @@ 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', - 'rest_framework.authentication.TokenAuthentication', ), } @@ -104,7 +102,7 @@ } } -DATABASES['default'] = dj_database_url.config(conn_max_age=600) + # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators @@ -144,7 +142,4 @@ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') - -if 'DATABASE_URL' in os.environ: - import dj_database_url - DATABASES = {'default': dj_database_url.config()} \ No newline at end of file +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' diff --git a/notes/admin.py b/notes/admin.py index 3cd144ff7..80a04dc03 100644 --- a/notes/admin.py +++ b/notes/admin.py @@ -5,6 +5,7 @@ + # Register your models here. class NoteAdmin(admin.ModelAdmin): readonly_fields=('created_at', 'last_modified') From bf6b01c1b722060ab5e084a568f2fe36fe68b89e Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 22:09:35 -0500 Subject: [PATCH 32/46] Messing with heroku --- Procfile | 6 +++++- djorg/settings.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Procfile b/Procfile index be138390c..f2599aa1c 100644 --- a/Procfile +++ b/Procfile @@ -1 +1,5 @@ -web: gunicorn djorg.wsgi --log-file - \ No newline at end of file +web: gunicorn djorg.wsgi --log-file - + +db_init: python db/manage.py version_control +db_version: python db/manage.py db_version +migrate: python db/manage.py upgrade \ No newline at end of file diff --git a/djorg/settings.py b/djorg/settings.py index e0813019b..ac25705ca 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -99,6 +99,8 @@ 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'USER': 'admin4', + 'PASSWORD': '123itworks', } } From 59f9382f173aebb3f9861a4ddf5125ec82b84c01 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 22:17:20 -0500 Subject: [PATCH 33/46] Heroku para funsies --- djorg/settings.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/djorg/settings.py b/djorg/settings.py index ac25705ca..7e8dcf2e9 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -145,3 +145,7 @@ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' + +if 'DATABASE_URL' in os.environ: + import dj_database_url + DATABASES = {'default': dj_database_url.config()} From 32db49d66eea1a8ba56e21ade64d1636a99f00fa Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 22:26:20 -0500 Subject: [PATCH 34/46] Able to create superuser Now have access to admin functions for app on heroku --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 9203be49d..705d0c4a1 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,17 @@ Fork this repo to use for your projects this week. * Add a Django front end to the data. * Brainstorm a list of 10 additional features users would find useful. * Implement the brainstormed list. + + +Added additional code to settings.py to connect table on heroku. + +in settings.py (at end of file) +----- +if 'DATABASE_URL' in os.environ: + import dj_database_url + DATABASES = {'default': dj_database_url.config()} + +in requirements.txt +------ +dj-database-url +psycopg2 \ No newline at end of file From c03d4403e4a587dba03c3a85a02994995bf6feaa Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 22:43:43 -0500 Subject: [PATCH 35/46] FrontPage --- djorg/urls.py | 3 +++ notes/views.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/djorg/urls.py b/djorg/urls.py index b2ffaf2a7..2d47ecdee 100644 --- a/djorg/urls.py +++ b/djorg/urls.py @@ -19,6 +19,7 @@ from rest_framework.authtoken import views from notes.api import PersonalNoteViewSet from quotes.api import PersonalQuoteViewSet +from notes.views import index router = routers.DefaultRouter() router.register(r'notes', PersonalNoteViewSet) @@ -28,6 +29,8 @@ path('admin/', admin.site.urls), path('api/', include(router.urls)), re_path(r'^api-token-auth/', views.obtain_auth_token), + path('api-token-auth/', views.obtain_auth_token), + path('', index), ] diff --git a/notes/views.py b/notes/views.py index 91ea44a21..ecbf5c911 100644 --- a/notes/views.py +++ b/notes/views.py @@ -1,3 +1,13 @@ from django.shortcuts import render # Create your views here. + +from django.http import HttpResponse + +# Create your views here. +def index(request): + return HttpResponse(""" + 1. Admin

+ 2. API

+ 3. API Token Auth + """) \ No newline at end of file From a3b13b5a59b27c0417c10ce9ca37e4ff16104d3f Mon Sep 17 00:00:00 2001 From: Huthman King Date: Fri, 7 Dec 2018 22:55:34 -0500 Subject: [PATCH 36/46] Spell --- notes/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes/views.py b/notes/views.py index ecbf5c911..53ea84f46 100644 --- a/notes/views.py +++ b/notes/views.py @@ -9,5 +9,5 @@ def index(request): return HttpResponse(""" 1. Admin

2. API

- 3. API Token Auth + 3. API Token Auth """) \ No newline at end of file From 5f203582c570afb259478c4904539d2baf6e3d4a Mon Sep 17 00:00:00 2001 From: Huthman King Date: Sat, 8 Dec 2018 01:29:35 -0500 Subject: [PATCH 37/46] Working on html --- notes/highlights.html | 9 +++++++++ notes/views.py | 4 ++++ 2 files changed, 13 insertions(+) create mode 100644 notes/highlights.html diff --git a/notes/highlights.html b/notes/highlights.html new file mode 100644 index 000000000..63b41cafe --- /dev/null +++ b/notes/highlights.html @@ -0,0 +1,9 @@ + + +

Hi there!

+

It works!

+ 1. Admin

+ 2. API

+ 3. API Token Auth + + \ No newline at end of file diff --git a/notes/views.py b/notes/views.py index 53ea84f46..9f79a31dc 100644 --- a/notes/views.py +++ b/notes/views.py @@ -5,6 +5,10 @@ from django.http import HttpResponse # Create your views here. + +def highlights(request): + return render(request, 'notes/highlights.html', {}) + def index(request): return HttpResponse(""" 1. Admin

From 6338a2c38d8408d0e6b07fe94eb4a5b01c948d8e Mon Sep 17 00:00:00 2001 From: Huthman King Date: Sat, 8 Dec 2018 01:36:04 -0500 Subject: [PATCH 38/46] url for html --- djorg/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/djorg/urls.py b/djorg/urls.py index 2d47ecdee..58527e58e 100644 --- a/djorg/urls.py +++ b/djorg/urls.py @@ -19,7 +19,7 @@ from rest_framework.authtoken import views from notes.api import PersonalNoteViewSet from quotes.api import PersonalQuoteViewSet -from notes.views import index +from notes.views import index, highlights router = routers.DefaultRouter() router.register(r'notes', PersonalNoteViewSet) @@ -30,7 +30,7 @@ path('api/', include(router.urls)), re_path(r'^api-token-auth/', views.obtain_auth_token), path('api-token-auth/', views.obtain_auth_token), - path('', index), + path('', index, highlights), ] From 324d5f578f02e823989b303b2eaf52463ccea2d4 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Sat, 8 Dec 2018 01:58:50 -0500 Subject: [PATCH 39/46] Rollback --- djorg/urls.py | 4 ++-- notes/views.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/djorg/urls.py b/djorg/urls.py index 58527e58e..2d47ecdee 100644 --- a/djorg/urls.py +++ b/djorg/urls.py @@ -19,7 +19,7 @@ from rest_framework.authtoken import views from notes.api import PersonalNoteViewSet from quotes.api import PersonalQuoteViewSet -from notes.views import index, highlights +from notes.views import index router = routers.DefaultRouter() router.register(r'notes', PersonalNoteViewSet) @@ -30,7 +30,7 @@ path('api/', include(router.urls)), re_path(r'^api-token-auth/', views.obtain_auth_token), path('api-token-auth/', views.obtain_auth_token), - path('', index, highlights), + path('', index), ] diff --git a/notes/views.py b/notes/views.py index 9f79a31dc..8b13b6d97 100644 --- a/notes/views.py +++ b/notes/views.py @@ -6,11 +6,10 @@ # Create your views here. -def highlights(request): - return render(request, 'notes/highlights.html', {}) def index(request): return HttpResponse(""" +

"Welcome to Django"

1. Admin

2. API

3. API Token Auth From e1fcae9ad0682a1e2530cd1bbb38827e457184ea Mon Sep 17 00:00:00 2001 From: Huthman King Date: Sat, 8 Dec 2018 02:03:14 -0500 Subject: [PATCH 40/46] Test --- notes/highlights.html | 6 ++++++ notes/views.py | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/notes/highlights.html b/notes/highlights.html index 63b41cafe..dc6dd6f94 100644 --- a/notes/highlights.html +++ b/notes/highlights.html @@ -5,5 +5,11 @@ 1. Admin

2. API

3. API Token Auth + """ +

"Welcome to Django"

+ 1. Admin

+ 2. API

+ 3. API Token Auth + """ \ No newline at end of file diff --git a/notes/views.py b/notes/views.py index 8b13b6d97..d7eb214cb 100644 --- a/notes/views.py +++ b/notes/views.py @@ -8,9 +8,5 @@ def index(request): - return HttpResponse(""" -

"Welcome to Django"

- 1. Admin

- 2. API

- 3. API Token Auth - """) \ No newline at end of file + + return render(request, 'highlights.html', context=context) \ No newline at end of file From 08247cbb7a54526f233a149b29ccccb29ca65e55 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Sat, 8 Dec 2018 02:05:22 -0500 Subject: [PATCH 41/46] bug --- notes/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes/views.py b/notes/views.py index d7eb214cb..44bba93c0 100644 --- a/notes/views.py +++ b/notes/views.py @@ -9,4 +9,4 @@ def index(request): - return render(request, 'highlights.html', context=context) \ No newline at end of file + return render(request, 'highlights.html') \ No newline at end of file From 6e1c946400e94ab2891a9fccae5f174493e5790b Mon Sep 17 00:00:00 2001 From: Huthman King Date: Sat, 8 Dec 2018 02:22:50 -0500 Subject: [PATCH 42/46] Reverting if html doesnt render --- notes/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes/views.py b/notes/views.py index 44bba93c0..0af646b96 100644 --- a/notes/views.py +++ b/notes/views.py @@ -9,4 +9,4 @@ def index(request): - return render(request, 'highlights.html') \ No newline at end of file + return render('highlights.html') \ No newline at end of file From 165d1c8b8d0c3c38532dad8d15a9e44b451e1fd9 Mon Sep 17 00:00:00 2001 From: Huthman King Date: Sat, 8 Dec 2018 02:27:30 -0500 Subject: [PATCH 43/46] render_to_response attempt --- notes/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/notes/views.py b/notes/views.py index 0af646b96..101b9f271 100644 --- a/notes/views.py +++ b/notes/views.py @@ -1,4 +1,5 @@ from django.shortcuts import render +from django.shortcuts import render_to_response # Create your views here. @@ -7,6 +8,5 @@ # Create your views here. -def index(request): - - return render('highlights.html') \ No newline at end of file +def index(request): + return render_to_response('notes/highlights.html') \ No newline at end of file From 75dd9b55e6507601b069c886c20f2b7c40cd351b Mon Sep 17 00:00:00 2001 From: Huthman King Date: Sat, 8 Dec 2018 02:31:07 -0500 Subject: [PATCH 44/46] httpresponse --- notes/views.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/notes/views.py b/notes/views.py index 101b9f271..b15fda555 100644 --- a/notes/views.py +++ b/notes/views.py @@ -1,12 +1,6 @@ -from django.shortcuts import render -from django.shortcuts import render_to_response - -# Create your views here. - from django.http import HttpResponse +from django.template import Context, loader -# Create your views here. - - -def index(request): - return render_to_response('notes/highlights.html') \ No newline at end of file +def index(request): + template = loader.get_template("notes/highlights.html") + return HttpResponse(template.render) \ No newline at end of file From 042c3fea700e2f3a96ec11e434497a68b2cde41a Mon Sep 17 00:00:00 2001 From: Huthman King Date: Sat, 8 Dec 2018 02:33:55 -0500 Subject: [PATCH 45/46] typo --- notes/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notes/views.py b/notes/views.py index b15fda555..e34ed6eb8 100644 --- a/notes/views.py +++ b/notes/views.py @@ -1,6 +1,7 @@ +from django.shortcuts import render from django.http import HttpResponse from django.template import Context, loader def index(request): template = loader.get_template("notes/highlights.html") - return HttpResponse(template.render) \ No newline at end of file + return HttpResponse(template.render()) \ No newline at end of file From 0512fdeb3861faf0d6d07a7982339c4085cb3b2d Mon Sep 17 00:00:00 2001 From: Huthman King Date: Sat, 8 Dec 2018 02:37:08 -0500 Subject: [PATCH 46/46] revert unable to load html at this time --- notes/views.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/notes/views.py b/notes/views.py index e34ed6eb8..8b13b6d97 100644 --- a/notes/views.py +++ b/notes/views.py @@ -1,7 +1,16 @@ from django.shortcuts import render + +# Create your views here. + from django.http import HttpResponse -from django.template import Context, loader + +# Create your views here. + def index(request): - template = loader.get_template("notes/highlights.html") - return HttpResponse(template.render()) \ No newline at end of file + return HttpResponse(""" +

"Welcome to Django"

+ 1. Admin

+ 2. API

+ 3. API Token Auth + """) \ No newline at end of file