Guest User

Untitled

a guest
Dec 25th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. Install Django(Latest) and Django Rest Framework
  2. ================================================
  3.  
  4. ### What is Django REST Framework?
  5. Django REST framework is a powerful and flexible toolkit for building Web APIs.
  6.  
  7. Some reasons you might want to use REST framework:
  8.  
  9. * The Web browsable API is a huge usability win for your developers.
  10. * Authentication policies including packages for OAuth1a and OAuth2.
  11. * Serialization that supports both ORM and non-ORM data sources.
  12. * Customizable all the way down - just use regular function-based views if you don't need the more powerful features.
  13. * Extensive documentation, and great community support.
  14. * Used and trusted by internationally recognised companies including Mozilla, Red Hat, Heroku, and Eventbrite.
  15.  
  16. ### Environment
  17.  
  18. * <b> Operating System</b> : Ubuntu 16.04 LTS (64-bit)
  19. * <b> Python</b> : 3.5.2
  20.  
  21. #### Create Virtual Environment
  22. ```
  23. python3 -m virtualenv venv
  24. ```
  25.  
  26. #### Activate Virtual Environment
  27. ```
  28. source venv/bin/activate
  29. ```
  30.  
  31. #### Install Latest Django
  32. ```
  33. pip install django
  34. ```
  35.  
  36. #### Install Django REST Framework
  37. ```
  38. pip install djangorestframework
  39. ```
  40.  
  41. #### Install Django Filter
  42. ```
  43. pip install django-filter
  44. ```
  45.  
  46. #### Install Markdown
  47. ```
  48. pip install Markdown
  49. ```
  50.  
  51. #### Install Ckeditor
  52. ```
  53. pip install django-ckeditor
  54. ```
  55.  
  56. #### Create A Django Project and Change to Project Directory
  57. ```
  58. django-admin startproject newslettersite
  59. cd newslettersite
  60. ```
  61.  
  62. #### Create An App
  63. ```
  64. python manage.py startapp newsletter
  65. ```
  66.  
  67. #### Run Project
  68. ```
  69. python manage.py runserver
  70. ```
  71.  
  72. #### Create Tables in Database
  73. ```
  74. python manage.py migrate
  75. ```
  76.  
  77. #### Make Migrations of Models and Reflect them in Database
  78. ```
  79. python manage.py makemigrations newsletter
  80. python manage.py migrate
  81.  
  82. ```
  83.  
  84. #### Open Python Shell Around Django API
  85. ```
  86. python manage.py shell
  87. ```
  88.  
  89. #### Create Super User
  90. ```
  91. python manage.py createsuperuser
  92. username:
  93. Email address:
  94. Password:
  95. ```
  96.  
  97. #### Settings for CKEDITOR in `settings.py`
  98. ```
  99. # starts added for static files
  100. from os.path import abspath, dirname, join, normpath, exists
  101. # Absolute filesystem path to the Django project directory:
  102. DJANGO_ROOT = dirname(abspath(__file__))
  103.  
  104. # Absolute filesystem path to the top-level project folder:
  105. SITE_ROOT = dirname(DJANGO_ROOT)
  106. STATIC_ROOT = join(SITE_ROOT, "site_media", "static")
  107. CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'
  108.  
  109. CKEDITOR_CONFIGS = {
  110. 'default':
  111. {
  112. 'autoParagraph': False,
  113. 'toolbar': 'basic',
  114. 'allowedContent': True,
  115. },
  116. }
  117.  
  118. # end added for static files
  119.  
  120. # Application definition
  121.  
  122. INSTALLED_APPS = [
  123. 'newsletter.apps.NewsletterConfig', # this is the app
  124. 'django.contrib.admin',
  125. 'django.contrib.auth',
  126. 'django.contrib.contenttypes',
  127. 'django.contrib.sessions',
  128. 'django.contrib.messages',
  129. 'django.contrib.staticfiles',
  130. 'rest_framework',
  131. 'ckeditor'
  132. ]
  133. ```
  134.  
  135. #### Create Static Files
  136. ```
  137. python manage.py collectstatic
  138. ```
  139.  
  140. #### Adding CKEditor in `models.py`
  141. ```
  142. from django.db import models
  143.  
  144. from ckeditor.fields import RichTextField
  145.  
  146. class Newsletter(models.Model):
  147. lead_text = RichTextField()
  148. ```
Add Comment
Please, Sign In to add comment