Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Install Django(Latest) and Django Rest Framework
- ================================================
- ### What is Django REST Framework?
- Django REST framework is a powerful and flexible toolkit for building Web APIs.
- Some reasons you might want to use REST framework:
- * The Web browsable API is a huge usability win for your developers.
- * Authentication policies including packages for OAuth1a and OAuth2.
- * Serialization that supports both ORM and non-ORM data sources.
- * Customizable all the way down - just use regular function-based views if you don't need the more powerful features.
- * Extensive documentation, and great community support.
- * Used and trusted by internationally recognised companies including Mozilla, Red Hat, Heroku, and Eventbrite.
- ### Environment
- * <b> Operating System</b> : Ubuntu 16.04 LTS (64-bit)
- * <b> Python</b> : 3.5.2
- #### Create Virtual Environment
- ```
- python3 -m virtualenv venv
- ```
- #### Activate Virtual Environment
- ```
- source venv/bin/activate
- ```
- #### Install Latest Django
- ```
- pip install django
- ```
- #### Install Django REST Framework
- ```
- pip install djangorestframework
- ```
- #### Install Django Filter
- ```
- pip install django-filter
- ```
- #### Install Markdown
- ```
- pip install Markdown
- ```
- #### Install Ckeditor
- ```
- pip install django-ckeditor
- ```
- #### Create A Django Project and Change to Project Directory
- ```
- django-admin startproject newslettersite
- cd newslettersite
- ```
- #### Create An App
- ```
- python manage.py startapp newsletter
- ```
- #### Run Project
- ```
- python manage.py runserver
- ```
- #### Create Tables in Database
- ```
- python manage.py migrate
- ```
- #### Make Migrations of Models and Reflect them in Database
- ```
- python manage.py makemigrations newsletter
- python manage.py migrate
- ```
- #### Open Python Shell Around Django API
- ```
- python manage.py shell
- ```
- #### Create Super User
- ```
- python manage.py createsuperuser
- username:
- Email address:
- Password:
- ```
- #### Settings for CKEDITOR in `settings.py`
- ```
- # starts added for static files
- from os.path import abspath, dirname, join, normpath, exists
- # Absolute filesystem path to the Django project directory:
- DJANGO_ROOT = dirname(abspath(__file__))
- # Absolute filesystem path to the top-level project folder:
- SITE_ROOT = dirname(DJANGO_ROOT)
- STATIC_ROOT = join(SITE_ROOT, "site_media", "static")
- CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'
- CKEDITOR_CONFIGS = {
- 'default':
- {
- 'autoParagraph': False,
- 'toolbar': 'basic',
- 'allowedContent': True,
- },
- }
- # end added for static files
- # Application definition
- INSTALLED_APPS = [
- 'newsletter.apps.NewsletterConfig', # this is the app
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'rest_framework',
- 'ckeditor'
- ]
- ```
- #### Create Static Files
- ```
- python manage.py collectstatic
- ```
- #### Adding CKEditor in `models.py`
- ```
- from django.db import models
- from ckeditor.fields import RichTextField
- class Newsletter(models.Model):
- lead_text = RichTextField()
- ```
Add Comment
Please, Sign In to add comment