Skip to content

Commit 0bbe842

Browse files
committed
currentDate
1 parent 425eb33 commit 0bbe842

36 files changed

Lines changed: 1176 additions & 0 deletions

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.pyc
2+
db.sqlite3
3+
venv/
4+
5+
__pycache__
6+
migrations
7+
Media

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
3+
# Simple Blogging Django Web App (Using GraphQL & Bootstrap)
4+
5+
6+
7+
## Installation:
8+
Pre-requisites:
9+
Install ` Python 3 `, ` pip ` and ` virtualenv `
10+
11+
1. Create a project folder
12+
13+
```bash
14+
$ mkdir project
15+
$ cd project
16+
```
17+
2. Create a python 3 virtualenv, and activate the environment to install requirements.
18+
```bash
19+
$ python3 -m venv env
20+
$ source env/bin/activate
21+
```
22+
3. Install the project dependencies from `requirements.txt`
23+
```
24+
(env)$ pip install -r requirements.txt
25+
```
26+
4. Clone the repository
27+
28+
```bash
29+
(env)$ git clone https://github.com/akhil-s-kumar/django-blog-app.git
30+
(env)$ cd django-blog-app
31+
```
32+
33+
34+
35+
## Run Instructions:
36+
37+
Activate virtual environment `env`. Give following commands:
38+
39+
```bash
40+
(env)$ python manage.py makemigrations
41+
(env)$ python manage.py makemigrations blogApp
42+
(env)$ python manage.py makemigrations users
43+
(env)$ python manage.py migrate
44+
(env)$ python manage.py createsuperuser
45+
(env)$ python manage.py runserver
46+
```
47+
48+
## Major Features:
49+
50+
1. Blog List View
51+
2. Recent Posts
52+
3. Category list
53+
4. Search
54+
5. Pagination
55+
6. Blog Detail View
56+
7. Login/Register
57+
8. Comment
58+
9. Create Blog Post
59+
10. Edit Profile

blog/__init__.py

Whitespace-only changes.

blog/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for blog project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings')
15+
16+
application = get_asgi_application()

blog/schema.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import graphene
2+
import blogApp.schema
3+
4+
class Query(blogApp.schema.Query, graphene.ObjectType):
5+
pass
6+
7+
class Mutation(blogApp.schema.Mutation, graphene.ObjectType):
8+
pass
9+
10+
schema = graphene.Schema(query=Query, mutation=Mutation)

blog/settings.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
"""
2+
Django settings for blog project.
3+
4+
Generated by 'django-admin startproject' using Django 3.1.5.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/3.1/ref/settings/
11+
"""
12+
13+
from pathlib import Path, os
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'jqx894oijedfnskmltruyjrt98hboirnhkonti0jtn0iwnb&w=w'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = ['*']
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'graphene_django',
35+
'users.apps.UsersConfig',
36+
'blogApp.apps.BlogappConfig',
37+
'django.contrib.admin',
38+
'django.contrib.auth',
39+
'django.contrib.contenttypes',
40+
'django.contrib.sessions',
41+
'django.contrib.messages',
42+
'django.contrib.staticfiles',
43+
'ckeditor',
44+
]
45+
46+
GRAPHENE = {
47+
'SCHEMA': 'blog.schema.schema'
48+
}
49+
50+
MIDDLEWARE = [
51+
'django.middleware.security.SecurityMiddleware',
52+
'django.contrib.sessions.middleware.SessionMiddleware',
53+
'django.middleware.common.CommonMiddleware',
54+
'django.middleware.csrf.CsrfViewMiddleware',
55+
'django.contrib.auth.middleware.AuthenticationMiddleware',
56+
'django.contrib.messages.middleware.MessageMiddleware',
57+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
58+
]
59+
60+
ROOT_URLCONF = 'blog.urls'
61+
62+
TEMPLATES = [
63+
{
64+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
65+
'DIRS': [os.path.join(BASE_DIR,'templates')],
66+
'APP_DIRS': True,
67+
'OPTIONS': {
68+
'context_processors': [
69+
'django.template.context_processors.debug',
70+
'django.template.context_processors.request',
71+
'django.contrib.auth.context_processors.auth',
72+
'django.contrib.messages.context_processors.messages',
73+
],
74+
},
75+
},
76+
]
77+
78+
WSGI_APPLICATION = 'blog.wsgi.application'
79+
80+
81+
# Database
82+
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
83+
84+
DATABASES = {
85+
'default': {
86+
'ENGINE': 'django.db.backends.sqlite3',
87+
'NAME': BASE_DIR / 'db.sqlite3',
88+
}
89+
}
90+
91+
92+
# Password validation
93+
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
94+
95+
AUTH_PASSWORD_VALIDATORS = [
96+
{
97+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
98+
},
99+
{
100+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
101+
},
102+
{
103+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
104+
},
105+
{
106+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
107+
},
108+
]
109+
110+
111+
# Internationalization
112+
# https://docs.djangoproject.com/en/3.1/topics/i18n/
113+
114+
LANGUAGE_CODE = 'en-us'
115+
116+
TIME_ZONE = 'UTC'
117+
118+
USE_I18N = True
119+
120+
USE_L10N = True
121+
122+
USE_TZ = True
123+
124+
125+
# Static files (CSS, JavaScript, Images)
126+
# https://docs.djangoproject.com/en/3.1/howto/static-files/
127+
128+
STATIC_URL = '/static/'
129+
STATICFILES_DIRS = [
130+
os.path.join(BASE_DIR, 'static')
131+
]
132+
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
133+
134+
MEDIA_URL = '/Media/'
135+
MEDIA_ROOT = os.path.join(BASE_DIR, 'Media')

blog/urls.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""blog URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/3.1/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.contrib import admin
17+
from django.urls import path, include
18+
from django.conf import settings
19+
from django.conf.urls.static import static
20+
from graphene_django.views import GraphQLView
21+
from blog.schema import schema
22+
from users import views as user_views
23+
24+
urlpatterns = [
25+
path('admin/', admin.site.urls),
26+
path('graphql/', GraphQLView.as_view(graphiql=True)),
27+
path('register/', user_views.register, name='register'),
28+
path('login/', user_views.login, name='login'),
29+
path('logout/', user_views.logout, name='logout'),
30+
path('', include('blogApp.urls')),
31+
]
32+
33+
urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

blog/utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import string
2+
import random
3+
from django.utils.text import slugify
4+
5+
6+
def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits):
7+
return ''.join(random.choice(chars) for _ in range(size))
8+
9+
10+
def unique_slug_generator(instance, new_slug=None):
11+
if new_slug is not None:
12+
slug = new_slug
13+
else:
14+
slug = slugify(instance.title)
15+
16+
Klass = instance.__class__
17+
qs_exists = Klass.objects.filter(slug=slug).exists()
18+
if qs_exists:
19+
new_slug = "{slug}-{randstr}".format(
20+
slug=slug,
21+
randstr=random_string_generator(size=4)
22+
)
23+
return unique_slug_generator(instance, new_slug=new_slug)
24+
return slug

blog/wsgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for blog project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings')
15+
16+
application = get_wsgi_application()

blogApp/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)