A dynamic content management system for publishing youtube videos and blog post in a single page web application.
MIT License
A dynamic content management system for publishing youtube videos and blog post in a single page web application. I developed this web app to place all my youtube video tutorials and related blog post links in one place.
Demo 1 : Django + PostgreSQL + Heroku | Source Code: Github Django
Demo 2 : React + Firebase | Source Code: Github React
If you know django, postgresql, bootstrap you can easily modify html template and backend according to your project needs. But if you just want a site like the demo Pythonbangla.com you can change the images in static directory in the project, and add contents from your or your client's youtube channel or blog post. To know how to setup, follow the table of contents.
Let assume our project name will be djangodemo
git clone https://github.com/mahmudahsan/pythonbangla.com.git djangodemo
cd djangodemo # Enter the project dir
pipenv install django
pipenv shell # Activate pipenv
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "YOUR_LOCAL_DB_NAME",
"USER": "YOUR_POSTGRESQL_USER_NAME",
"PASSWORD": "YOUR_POSTGRESQL_PASSWORD",
"HOST": "localhost",
"PORT": "5432", # usually this port unless your port is different
}
}
python3 manage.py migrate
python3 manage.py runserver
CONTROL-C
python3 manage.py createsuperuser
python3 manage.py runserver
You will see the following admin panel with 4 tables
You will see the following form
Now fill the form for our demo purpose. In later you can modify/remove/add anything according to your requirments. After filling, SAVE the form.
Column | Data |
---|---|
Title English | Python Beginner |
Title Other | |
Short Description | |
Image Name | py-beg.png |
Topic Type | Youtube |
py-beg.png image already stored in projects djangodemo/static/img/py-beg.png. So if you want to use other image, please put that on this directory and mention the name in the form.
You will see the following form. Fill with some data like the demo and click SAVE.
You will see the following web page
Now visit http://127.0.0.1:8000 again to see the updates
Django by default doesn't support serving static files in production. So the best and recommended way to upload static files in CDN network. In this case, I like Amazon S3 CDN and its super easy to use.
First you need to create a Amazon Aws account
You have to create S3 bucket/container. To know how to proceed follow this tutorial
Install two new libraries
pipenv install boto3
pipenv install django-storages
INSTALLED_APPS = [
...,
'storages',
'main_app'
]
AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''
AWS_STORAGE_BUCKET_NAME = ''
AWS_S3_CUSTOM_DOMAIN = 's3.us-east-2.amazonaws.com/%s' % AWS_STORAGE_BUCKET_NAME
AWS_S3_OBJECT_PARAMETERS = {
'CacheControl': 'max-age=86400',
}
AWS_LOCATION = 'static'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
python3 manage.py collectstatic
Well now finally we can deploy our project in web server. For me, I found it is quite easy to use Heroku one of the popular python app hosting site. Heroku also has free tier package. So you can upload any python web project there, test and if satisified you can upgrade to premium service. Then you can add your own domain. Also heroku provides PostgreSQL service as well.
touch Procfile
web: gunicorn pythonbangla_project.wsgi --log-file -
pipenv install gunicorn
heroku login
heroku create django-demo-2018 # if this name django-demo-2018 available you can use otherwise try different name
# OR
heroku create # it will generate a random name for heroku project
heroku git:remote -a django-demo-2018 # in your case may be change django-demo-2018 to the name you selected or get randomly from heroku
heroku config:set DISABLE_COLLECTSTATIC=1
visit heroku dashboard click your app
Then click Heroku Postgres within Installed add-ons section
Then go to settings and click view database credentials
Now copy those info and update your django project's settins.py DATABASES->Default section
Add '*' in Allowed hosts in settings.py
DEBUG = False # first test it with False, if everythin runs successully then make it True, commit and push again
ALLOWED_HOSTS = ['*']
git add -A
git commit -m "heroku config updated"
git push heroku master
# OR if you use a different git branch in your machine then run
git push heroku LOCAL_BRANCH_NAME:master
heroku ps:scale web=1
If you don't want to use Amazon S3 or other CDN service and want to server static contents from heroku then you can follow this way to solve the problem.
pipenv install whitenoise
'django.contrib.messages',
'whitenoise.runserver_nostatic', # whitenoise
'django.contrib.staticfiles',
'main_app'
'django.contrib.sessions.middleware.SessionMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware', # whitenoise
'django.middleware.common.CommonMiddleware',
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') # new!
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' #new
heroku config:unset DISABLE_COLLECTSTATIC=1
git add -A
git commit -m "Whitenoise config added"
If your up the project in heroku and use their premium service and add a domain, heroku will automatically add a SSL so you can use https instead of http.
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
If you want to contribute on this project, you're welcome to fork the project and submit a pull request. Just try to not break the existing things.
Feel free to open an issue, or find me @mahmudahsan on Twitter.