From 2a3fa27ce29302dcf228879ad690c653fd70e424 Mon Sep 17 00:00:00 2001 From: shivstha Date: Wed, 7 Oct 2020 14:36:24 +0545 Subject: [PATCH 1/2] updated to django version 3 --- .idea/.gitignore | 3 ++ .idea/Django_blog.iml | 8 +++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++ .idea/misc.xml | 7 ++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ README.md | 19 +++++++++++ blog/admin.py | 1 + blog/migrations/0005_comment_tags.py | 20 ++++++++++++ blog/migrations/0006_auto_20201007_1355.py | 24 ++++++++++++++ blog/models.py | 3 +- mysite/settings.py | 32 ++++++------------- mysite/urls.py | 2 +- requirements.txt | 9 ++++++ requirments.txt | 6 ---- templates/index.html | 3 +- templates/post_detail.html | 1 + 17 files changed, 126 insertions(+), 32 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/Django_blog.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 blog/migrations/0005_comment_tags.py create mode 100644 blog/migrations/0006_auto_20201007_1355.py create mode 100644 requirements.txt delete mode 100755 requirments.txt diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Django_blog.iml b/.idea/Django_blog.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/Django_blog.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7a85af6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b99b72d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index c5e9f49..03d2e4e 100755 --- a/README.md +++ b/README.md @@ -2,6 +2,25 @@ A blog application made on Django. +## To run this project follow these steps: +```javascript +git clone https://github.com/TheAbhijeet/Django_blog.git +``` +```python +pip install -r requirements.txt +``` +```python +python manage.py migrate +``` +```python +python manage.py runserver +``` + +### To add blog posts first create superuser account and write from django admin panel(http://127.0.0.1:8000/admin) +```python +python manage.py createsuperuser +``` + ![ezgif com-video-to-gif](https://user-images.githubusercontent.com/38559396/55287491-12c4de80-53c7-11e9-8c6a-3f02b79ba9ca.gif) **Release 1.0** -Blog application made with Django, To learn more read https://djangocentral.com/building-a-blog-application-with-django diff --git a/blog/admin.py b/blog/admin.py index fa103d5..1ed8ee5 100755 --- a/blog/admin.py +++ b/blog/admin.py @@ -3,6 +3,7 @@ from django_summernote.admin import SummernoteModelAdmin + class PostAdmin(SummernoteModelAdmin): list_display = ('title', 'slug', 'status', 'created_on') list_filter = ('status', 'created_on') diff --git a/blog/migrations/0005_comment_tags.py b/blog/migrations/0005_comment_tags.py new file mode 100644 index 0000000..c98ce44 --- /dev/null +++ b/blog/migrations/0005_comment_tags.py @@ -0,0 +1,20 @@ +# Generated by Django 3.0.3 on 2020-10-07 08:06 + +from django.db import migrations +import taggit.managers + + +class Migration(migrations.Migration): + + dependencies = [ + ('taggit', '0003_taggeditem_add_unique_index'), + ('blog', '0004_auto_20191015_0853'), + ] + + operations = [ + migrations.AddField( + model_name='comment', + name='tags', + field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'), + ), + ] diff --git a/blog/migrations/0006_auto_20201007_1355.py b/blog/migrations/0006_auto_20201007_1355.py new file mode 100644 index 0000000..41f8f64 --- /dev/null +++ b/blog/migrations/0006_auto_20201007_1355.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.3 on 2020-10-07 08:10 + +from django.db import migrations +import taggit.managers + + +class Migration(migrations.Migration): + + dependencies = [ + ('taggit', '0003_taggeditem_add_unique_index'), + ('blog', '0005_comment_tags'), + ] + + operations = [ + migrations.RemoveField( + model_name='comment', + name='tags', + ), + migrations.AddField( + model_name='post', + name='tags', + field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'), + ), + ] diff --git a/blog/models.py b/blog/models.py index d45847d..c0f7b7a 100755 --- a/blog/models.py +++ b/blog/models.py @@ -1,6 +1,6 @@ from django.db import models from django.contrib.auth.models import User - +from taggit.managers import TaggableManager STATUS = ((0, "Draft"), (1, "Publish")) @@ -13,6 +13,7 @@ class Post(models.Model): ) updated_on = models.DateTimeField(auto_now=True) content = models.TextField() + tags = TaggableManager() created_on = models.DateTimeField(auto_now_add=True) status = models.IntegerField(choices=STATUS, default=0) diff --git a/mysite/settings.py b/mysite/settings.py index 0317a9e..87ebeb9 100755 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -1,13 +1,13 @@ """ Django settings for mysite project. -Generated by 'django-admin startproject' using Django 2.1.7. +Generated by 'django-admin startproject' using Django 3.0.3. For more information on this file, see -https://docs.djangoproject.com/en/2.1/topics/settings/ +https://docs.djangoproject.com/en/3.0/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/2.1/ref/settings/ +https://docs.djangoproject.com/en/3.0/ref/settings/ """ import os @@ -16,9 +16,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TEMPLATES_DIR = os.path.join(BASE_DIR, 'templates') - # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '0x!b#(1*cd73w$&azzc6p+essg7v=g80ls#z&xcx*mpemx&@9$' @@ -28,7 +27,6 @@ ALLOWED_HOSTS = [] - # Application definition INSTALLED_APPS = [ @@ -38,14 +36,13 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - + 'django.contrib.sitemaps', + 'taggit', 'blog', 'crispy_forms', 'django_summernote', ] -INSTALLED_APPS += ( 'django.contrib.sitemaps',) - MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -76,7 +73,6 @@ WSGI_APPLICATION = 'mysite.wsgi.application' - # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases @@ -87,7 +83,6 @@ } } - # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators @@ -106,7 +101,6 @@ }, ] - # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ @@ -120,7 +114,6 @@ USE_TZ = True - # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.1/howto/static-files/ @@ -129,19 +122,10 @@ # Location of static files STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ] - -STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') - - - - - - - +STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') CRISPY_TEMPLATE_PACK = 'bootstrap4' - # Media paths # Base url to serve media files @@ -149,3 +133,5 @@ # Path where media is stored MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') + +X_FRAME_OPTIONS = 'SAMEORIGIN' diff --git a/mysite/urls.py b/mysite/urls.py index 9bd3029..598f466 100755 --- a/mysite/urls.py +++ b/mysite/urls.py @@ -1,7 +1,7 @@ """mysite URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/2.1/topics/http/urls/ + https://docs.djangoproject.com/en/3.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e6c5431 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +asgiref==3.2.10 +certifi==2020.6.20 +Django==3.0.3 +django-crispy-forms==1.9.2 +django-summernote==0.8.11.6 +django-taggit==1.3.0 +pytz==2020.1 +sqlparse==0.3.1 +wincertstore==0.2 diff --git a/requirments.txt b/requirments.txt deleted file mode 100755 index 127268f..0000000 --- a/requirments.txt +++ /dev/null @@ -1,6 +0,0 @@ -Django==2.2.8 -django-crispy-forms==1.8.1 -django-summernote==0.8.11.4 -pkg-resources==0.0.0 -pytz==2019.3 -sqlparse==0.3.0 diff --git a/templates/index.html b/templates/index.html index c17c464..cff5338 100755 --- a/templates/index.html +++ b/templates/index.html @@ -29,8 +29,9 @@

Welcome to my awesome Blog

{{ post.title }}

{{ post.author }} | {{ post.created_on}}

+

Tags: {{ post.tags.all|join:", " }}

-

{{post.content|slice:":200" }}

+

{{post.content|safe|truncatewords:200 }}

Read More →
diff --git a/templates/post_detail.html b/templates/post_detail.html index 658691a..0de33b1 100755 --- a/templates/post_detail.html +++ b/templates/post_detail.html @@ -7,6 +7,7 @@

{% block title %} {{ post.title }} {% endblock title %}

{{ post.author }} | {{ post.created_on }}

+

Tags: {{ post.tags.all|join:", " }}

{{ post.content | safe }}

From 1a6d9709ab96b981a7ddff9a6ada89f81fc68f46 Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 9 Oct 2020 03:30:41 +0300 Subject: [PATCH 2/2] added a working contact page --- .vscode/settings.json | 3 ++ blog/admin.py | 3 +- blog/migrations/0007_contactmessage.py | 21 ++++++++++ blog/migrations/0008_auto_20201009_0328.py | 18 +++++++++ blog/models.py | 8 ++++ blog/urls.py | 1 + blog/views.py | 14 ++++++- static/css/base.css | 11 +++++ templates/base.html | 2 +- templates/contact.html | 47 ++++++++++++++++++++++ 10 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 blog/migrations/0007_contactmessage.py create mode 100644 blog/migrations/0008_auto_20201009_0328.py create mode 100644 templates/contact.html diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a1c4910 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "compile-hero.disable-compile-files-on-did-save-code": true +} \ No newline at end of file diff --git a/blog/admin.py b/blog/admin.py index 1ed8ee5..a40599c 100755 --- a/blog/admin.py +++ b/blog/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import Post, Comment +from .models import Post, Comment,contactmessage from django_summernote.admin import SummernoteModelAdmin @@ -25,3 +25,4 @@ def approve_comments(self, request, queryset): admin.site.register(Post, PostAdmin) +admin.site.register(contactmessage) diff --git a/blog/migrations/0007_contactmessage.py b/blog/migrations/0007_contactmessage.py new file mode 100644 index 0000000..a45eab4 --- /dev/null +++ b/blog/migrations/0007_contactmessage.py @@ -0,0 +1,21 @@ +# Generated by Django 3.0.3 on 2020-10-09 00:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0006_auto_20201007_1355'), + ] + + operations = [ + migrations.CreateModel( + name='contactmessage', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('email', models.EmailField(max_length=254)), + ('message', models.CharField(max_length=5550)), + ], + ), + ] diff --git a/blog/migrations/0008_auto_20201009_0328.py b/blog/migrations/0008_auto_20201009_0328.py new file mode 100644 index 0000000..b7f650d --- /dev/null +++ b/blog/migrations/0008_auto_20201009_0328.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.3 on 2020-10-09 00:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0007_contactmessage'), + ] + + operations = [ + migrations.AlterField( + model_name='contactmessage', + name='message', + field=models.TextField(max_length=5550), + ), + ] diff --git a/blog/models.py b/blog/models.py index c0f7b7a..8d6e276 100755 --- a/blog/models.py +++ b/blog/models.py @@ -42,3 +42,11 @@ class Meta: def __str__(self): return "Comment {} by {}".format(self.body, self.name) + + +class contactmessage(models.Model): + email = models.EmailField(max_length=254) + message = models.TextField(max_length=5550) + + def __str__(self): + return self.email \ No newline at end of file diff --git a/blog/urls.py b/blog/urls.py index e507e05..4edcc93 100755 --- a/blog/urls.py +++ b/blog/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ path("feed/rss", LatestPostsFeed(), name="post_feed"), + path("conact/",views.contact,name="contact"), path("feed/atom", AtomSiteNewsFeed()), path("", views.PostList.as_view(), name="home"), # path('/', views.PostDetail.as_view(), name='post_detail'), diff --git a/blog/views.py b/blog/views.py index edc1754..f3786d8 100755 --- a/blog/views.py +++ b/blog/views.py @@ -1,7 +1,8 @@ from django.views import generic -from .models import Post +from .models import Post,contactmessage from .forms import CommentForm -from django.shortcuts import render, get_object_or_404 +from django.shortcuts import render, get_object_or_404,redirect + class PostList(generic.ListView): @@ -45,3 +46,12 @@ def post_detail(request, slug): }, ) +def contact(request): + if request.method == "POST": + email = request.POST['email'] + message = request.POST['message'] + newmage = contactmessage(email=email,message=message) + newmage.save() + return redirect("/") + context = {} + return render(request,'contact.html',context) \ No newline at end of file diff --git a/static/css/base.css b/static/css/base.css index 1ca6f00..e43d210 100755 --- a/static/css/base.css +++ b/static/css/base.css @@ -24,4 +24,15 @@ body { .card { box-shadow: 0 16px 48px #E3E7EB; +} + + + +/* contact page */ +.contact-message{ + margin-top: 30px; + align-items: center; +} +.message-form{ + margin: 0 auto; } \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 499bfd5..b4551fd 100755 --- a/templates/base.html +++ b/templates/base.html @@ -41,7 +41,7 @@ Policy diff --git a/templates/contact.html b/templates/contact.html new file mode 100644 index 0000000..5faba81 --- /dev/null +++ b/templates/contact.html @@ -0,0 +1,47 @@ +{% extends "base.html" %} + + +{% block content %} + +
+
+
+
+
+
+

Contact us at anytime

+

Feel like getting in touch! Reachout to us now   +

+
+
+
+
+ +
+ +
+
+
+
+
+ {% csrf_token %} +
+ + + We'll never share your email with anyone else. +
+
+ + + + +
+ + +
+
+
+
+
+ +{% endblock content %} \ No newline at end of file