您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

getting_started.rst 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. ============================
  2. Start building your own shop
  3. ============================
  4. For simplicity, let's assume you're building a new e-commerce project from
  5. scratch and have decided to use Oscar. Let's call this shop 'frobshop'
  6. .. tip::
  7. You can always review the set-up of the `Sandbox site`_ in case you have
  8. trouble with the below instructions.
  9. .. _`Sandbox site`: https://github.com/tangentlabs/django-oscar/tree/releases/0.2/sandbox
  10. Install by hand
  11. ===============
  12. Install Oscar (which will install Django as a dependency), then create the
  13. project::
  14. pip install django-oscar
  15. django-admin.py startproject frobshop
  16. This will create a folder ``frobshop`` for your project.
  17. Settings
  18. --------
  19. Now edit your settings file ``frobshop.frobshop.settings.py`` to specify a
  20. database (we use SQLite for simplicity)::
  21. DATABASES = {
  22. 'default': {
  23. 'ENGINE': 'django.db.backends.sqlite3',
  24. 'NAME': 'db.sqlite3',
  25. 'USER': '',
  26. 'PASSWORD': '',
  27. 'HOST': '',
  28. 'PORT': '',
  29. }
  30. }
  31. then add ``oscar.apps.basket.middleware.BasketMiddleware`` to ``MIDDLEWARE_CLASSES``, and
  32. set ``TEMPLATE_CONTEXT_PROCESSORS`` to::
  33. TEMPLATE_CONTEXT_PROCESSORS = (
  34. "django.contrib.auth.context_processors.auth",
  35. "django.core.context_processors.request",
  36. "django.core.context_processors.debug",
  37. "django.core.context_processors.i18n",
  38. "django.core.context_processors.media",
  39. "django.core.context_processors.static",
  40. "django.contrib.messages.context_processors.messages",
  41. 'oscar.apps.search.context_processors.search_form',
  42. 'oscar.apps.promotions.context_processors.promotions',
  43. 'oscar.apps.checkout.context_processors.checkout',
  44. 'oscar.apps.customer.notifications.context_processors.notifications',
  45. 'oscar.core.context_processors.metadata',
  46. )
  47. Next, modify ``INSTALLED_APPS`` to be a list, add ``South`` and append Oscar's core apps::
  48. from oscar import get_core_apps
  49. INSTALLED_APPS = [
  50. 'django.contrib.auth',
  51. 'django.contrib.contenttypes',
  52. 'django.contrib.sessions',
  53. 'django.contrib.sites',
  54. 'django.contrib.messages',
  55. 'django.contrib.flatpages',
  56. ...
  57. 'south',
  58. ] + get_core_apps()
  59. Note that Oscar requires ``django.contrib.messages`` and
  60. ``django.contrib.flatpages`` which aren't included by default.
  61. Now set your auth backends to::
  62. AUTHENTICATION_BACKENDS = (
  63. 'oscar.apps.customer.auth_backends.Emailbackend',
  64. 'django.contrib.auth.backends.ModelBackend',
  65. )
  66. to allow customers to sign in using an email address rather than a username.
  67. Modify your ``TEMPLATE_DIRS`` to include the main Oscar template directory::
  68. from oscar import OSCAR_MAIN_TEMPLATE_DIR
  69. TEMPLATE_DIRS = TEMPLATE_DIRS + (OSCAR_MAIN_TEMPLATE_DIR,)
  70. Oscar currently uses Haystack for search so you need to specify::
  71. HAYSTACK_CONNECTIONS = {
  72. 'default': {
  73. 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
  74. },
  75. }
  76. When moving towards production, you'll obviously need to switch to a real search
  77. backend.
  78. The last addition to the settings file is to import all of Oscar's default settings::
  79. from oscar.defaults import *
  80. URLs
  81. ----
  82. Alter your ``frobshop/urls.py`` to include Oscar's URLs::
  83. from django.conf.urls import patterns, include, url
  84. from oscar.app import shop
  85. urlpatterns = patterns('',
  86. (r'', include(shop.urls))
  87. )
  88. Database
  89. --------
  90. Then create the database and the shop should be browsable::
  91. python manage.py syncdb --noinput
  92. python manage.py migrate
  93. You should now have a running Oscar install that you can browse.
  94. Install using Tangent's boilerplate django project
  95. ==================================================
  96. The easiest way to get started is to use Tangent's `template django project`_
  97. although it is tailored to an agency structure which may not suit everyone.
  98. .. _`template django project`: https://github.com/tangentlabs/tangent-django-boilerplate
  99. Set up a virtualenv, and create a new project using the ``startproject``
  100. management command::
  101. mkvirtualenv frobshop
  102. pip install Django
  103. django-admin.py startproject frobshop \
  104. --template=https://github.com/tangentlabs/tangent-django-boilerplate/zipball/master
  105. This will create a folder ``frobshop`` which is an entire templated project that
  106. follows Tangent's conventions. The structure is::
  107. frobshop/
  108. docs/
  109. www/
  110. conf/
  111. deploy/
  112. public/
  113. static/
  114. templates/
  115. manage.py
  116. settings.py
  117. settings_test.py
  118. urls.py
  119. urls_oscar.py
  120. README.rst
  121. fabconfig.py
  122. fabfile.py
  123. deploy-to-test.sh
  124. deploy-to-stage.sh
  125. deploy-to-prod.sh
  126. Replace a few files with Oscar-specific versions (the templated project can be
  127. used for non-Oscar projects too)::
  128. mv frobshop/www/urls{_oscar,}.py
  129. mv frobshop/www/deploy/requirements{_oscar,}.txt
  130. mv frobshop/www/conf/default{_oscar,}.py
  131. Install dependencies::
  132. cd frobshop/www
  133. pip install -r deploy/requirements.txt
  134. Create database::
  135. python manage.py syncdb --noinput
  136. python manage.py migrate
  137. And that should be it.
  138. Next steps
  139. ==========
  140. The next step is to implement the business logic of your domain on top of
  141. Oscar. The fun part.