Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

getting_started.rst 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.core.context_processors.metadata',
  45. )
  46. Next, modify ``INSTALLED_APPS`` to be a list, add ``South`` and append Oscar's core apps::
  47. from oscar import get_core_apps
  48. INSTALLED_APPS = [
  49. 'django.contrib.auth',
  50. ...
  51. 'south',
  52. ] + get_core_apps()
  53. and set your auth backends to::
  54. AUTHENTICATION_BACKENDS = (
  55. 'oscar.apps.customer.auth_backends.Emailbackend',
  56. 'django.contrib.auth.backends.ModelBackend',
  57. )
  58. to allow customers to sign in using an email address rather than a username.
  59. Modify your ``TEMPLATE_DIRS`` to include the main Oscar template directory::
  60. from oscar import OSCAR_MAIN_TEMPLATE_DIR
  61. TEMPLATE_DIRS = TEMPLATE_DIRS + (OSCAR_MAIN_TEMPLATE_DIR,)
  62. Oscar currently uses Haystack for search so you need to specify::
  63. HAYSTACK_SITECONF = 'oscar.search_sites'
  64. HAYSTACK_SEARCH_ENGINE = 'dummy'
  65. When moving towards production, you'll obviously need to switch to a real search
  66. backend.
  67. The last addition to the settings file is to import all of Oscar's default settings::
  68. from oscar.defaults import *
  69. URLs
  70. ----
  71. Alter your ``frobshop/urls.py`` to include Oscar's URLs::
  72. from django.conf.urls import patterns, include, url
  73. from oscar.app import shop
  74. urlpatterns = ('',
  75. (r'', include(shop.urls))
  76. )
  77. Database
  78. --------
  79. Then create the database and the shop should be browsable::
  80. python manage.py syncdb --noinput
  81. python manage.py migrate
  82. You should now have a running Oscar install that you can browse.
  83. Install using Tangent's boilerplate django project
  84. ==================================================
  85. The easiest way to get started is to use Tangent's `template django project`_
  86. although it is tailored to an agency structure which may not suit everyone.
  87. .. _`template django project`: https://github.com/tangentlabs/tangent-django-boilerplate
  88. Set up a virtualenv, and create a new project using the ``startproject``
  89. management command::
  90. mkvirtualenv frobshop
  91. pip install Django
  92. django-admin.py startproject frobshop \
  93. --template=https://github.com/tangentlabs/tangent-django-boilerplate/zipball/master
  94. This will create a folder ``frobshop`` which is an entire templated project that
  95. follows Tangent's conventions. The structure is::
  96. frobshop/
  97. docs/
  98. www/
  99. conf/
  100. deploy/
  101. public/
  102. static/
  103. templates/
  104. manage.py
  105. settings.py
  106. settings_test.py
  107. urls.py
  108. urls_oscar.py
  109. README.rst
  110. fabconfig.py
  111. fabfile.py
  112. deploy-to-test.sh
  113. deploy-to-stage.sh
  114. deploy-to-prod.sh
  115. Replace a few files with Oscar-specific versions (the templated project can be
  116. used for non-Oscar projects too)::
  117. mv frobshop/www/urls{_oscar,}.py
  118. mv frobshop/www/deploy/requirements{_oscar,}.py
  119. mv frobshop/www/conf/default{_oscar,}.py
  120. Install dependencies::
  121. cd frobshop/www
  122. pip install -r deploy/requirements.txt
  123. Create database::
  124. python manage.py syncdb --noinput
  125. python manage.py migrate
  126. And that should be it.
  127. Next steps
  128. ==========
  129. The next step is to implement the business logic of your domain on top of
  130. Oscar. The fun part.