项目作者: arihant-001

项目描述 :
A small e-commerce website
高级语言: Python
项目地址: git://github.com/arihant-001/django-cart.git
创建时间: 2020-08-10T15:05:06Z
项目社区:https://github.com/arihant-001/django-cart

开源协议:MIT License

下载


Django-Cart

django-cart is a basic model for ecommerce websites implemented using django and postres.

Demo Website

View demo site at django-cart

  1. user credentials
  2. username: test
  3. password: test@password

View admin site at admin

  1. user credentials
  2. username: admin
  3. password: admin

Project Setup on localhost

Clone the repository

  1. $ git clone https://github.com/arihant-001/django-cart.git

Install and activate virtual environment

  1. # install virtualenv for easily setting up virtual environment
  2. $ sudo pip3 install virtualenv
  3. # create a new virtual environment with name venv
  4. $ virtualenv -p python3 venv
  5. # activate the venv environment
  6. $ source venv/bin/activate
  7. # If your shell changes like below, then you are ready
  8. (venv) $

Install Requirements

  1. $ pip3 install -r requirements.txt

Run the project

  1. # inside the cloned directory
  2. $ python3 manage.py runserver

Docker

Set the database config in django-cart/settings.py as:

  1. DATABASES = {
  2. 'default': {
  3. 'ENGINE': 'django.db.backends.postgresql',
  4. 'NAME': 'postgres',
  5. 'USER': 'postgres',
  6. 'PASSWORD': 'postgres',
  7. 'HOST': 'db',
  8. 'PORT': 5432,
  9. }
  10. }

Install docker and docker-compose

Build and run the container using docker-compose

  1. # Build and start containers
  2. $ doker-compose up --build
  3. # create tables
  4. $ docker-compose exec web python manage.py migrate
  5. # create admin
  6. $ docker-compose exec web python manage.py createsuperuser

Create dummy data

  1. # open web container shell
  2. $ docker exec -it django-cart_web_1 bash
  3. # go to scripts
  4. $ cd scripts
  5. # download data
  6. $ python bb_scrapper.py
  7. # populate data in db
  8. $ python populate_product.py

Heroku

Creating new app using heroku cli

  1. # create an app on heroku with a unique_app_name
  2. $ heroku create unique_app_name
  3. # create tables in database
  4. $ heroku run python manage.py migrate
  5. # create an admin
  6. $ heroku run python manage.py createsuperuser

Setup production variables

create a secret key for production using a key generator

  1. # set the above key in production
  2. $ heroku config:set DJANGO_SECRET_KEY='!oxq(v+a2h-lk!%434t_$g)7li%%318gn6bw1$j1e%7j#h%ahv'
  3. # disable debug
  4. $ heroku config:set DJANGO_DEBUG=False

Add host in settings

Open /django-cart/settings.py and change the ALLOWED_HOSTS setting to include your base app url

  1. ALLOWED_HOSTS = ['<your app URL without the https:// prefix>.herokuapp.com','localhost']

deploy the updated app

  1. git add -A
  2. git commit -m 'Update ALLOWED_HOSTS with site and development server URL'
  3. git push heroku master