GithubHelp home page GithubHelp logo

lazidoca / react-django-blog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yukiumetsu/react-django-blog

0.0 1.0 0.0 3.79 MB

This is a blog project with react.js/next.js frontend, django backend, powered by linux, nginx, gunicorn, redis in docker containers.

Dockerfile 0.19% Python 45.69% CSS 22.27% JavaScript 31.85%

react-django-blog's Introduction

react-django-blog

This is a blog project with react.js/next.js frontend, django backend, powered by linux, nginx, gunicorn, redis in docker containers.

Technology stack

Frontend: Next.js (React.js) - server Node.js
Backend: Django (python framework)
Cache system: Redis
Web server: Nginx
WSGI (Web Server Getaway Interface): Gunicorn
Database: postgresql

initialize docker containers

docker-compose up
docker-compose up -d (runs in background)

access in web browser

access to localhost:5555

Nginx config

access to /api/ or /admin/ => django application
access to everything else => Next.js application
/static/ => specified static folder
/media/ => specified media folder (user uploaded media)

.env file

frontend: create a .env.dev file in frontend folder according to .env.sample.
backend: create a .env.dev file in backend folder according to .env.sample.

tips using pytest

  1. add DJANGO_SETTINGS_MODULE=blog.settings in your .env file.
  2. Do NOT add "init.py" file under test folder. Otherwise, pytest can't find modules for some reason.
  3. start pytest
    docker container exec -it backend sh -c "pytest"

loading initial data

  1. if "backend/countries/fixtures/countries_fixtures.json" doesn't exist, do the following:
    docker container exec -it backend sh -c "python countries_data_convert.py"
    this will create the countries_fixtures.json file.
  2. load the data from the json file
    docker container exec -it backend sh -c "python manage.py loaddata countries/fixtures/countries_fixtures.json"
    ** load all the initial data at once** docker container exec -it backend sh -c "python3 manage.py loaddata /fixtures/.json"

create superuser

I created a script to create a super user in one command.
Edit email and password in backend/scripts/add_superuser.py
docker container exec -it backend sh -c "python manage.py runscript add_superuser"

reset migrations

I created a script reset migrations in dev environment.

  1. drop the database.
  2. remove all the migration files.
  3. make new migration files and migrate again.
    docker container exec -it backend sh -c "python manage.py runscript reset_migrate" or
    docker container exec -it backend sh -c "python cmanage.py resetmigrate"

shortcuts for creating a new app!

docker container exec -it backend sh -c "python cmanage.py startapp app_name singular_app_name"
*singular_app_name is optional
This command creates a folder and scripts including default models ...etc like always but also..
basic serializers.py, test file in tests folder, urls.py, add basic model views script in views.py
It also adds the app in the INSTALLED_APPS in the settings.py!!

commands to create basic serializers.py, urls.py, add basic api scripts to views.py

docker container exec -it backend sh -c "python manage.py runscript add_api --script-args app_name singular_app_name"
*singular_app_name is optional. If it is empty, singular will be app_name without last plural "s" if any.

Redis cache:

You should consider caching the result of a request when the following cases are true:

  • rendering the page involves a lot of database queries and/or business logic,
  • the page is visited frequently by your users,
  • the data is the same for every user,
  • and the data does not change often.
    CACHE_TTL = getattr(settings, 'CACHE_TTL', DEFAULT_TIMEOUT)
    @cache_page(CACHE_TTL)
    def get_posts():

react-django-blog's People

Contributors

yukiumetsu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.