<commit_before>Installation
==============================

This section shows how to install DMP with a new project as well as an existing project.

What kind of project do you have?

.. contents::
    :depth: 3


New Project
-----------------------------

Install Python and ensure you can run ``python3`` (or ``python``) at the command prompt. The framework requires Python 3.4+.

Install Django, Mako, and DMP
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

DMP works with Django 1.9+, including the 2.0 releases.

Install with the python installer:

::

    pip3 install django-mako-plus

Note that on Windows machines, ``pip3`` may need to be replaced with ``pip``:

::

    pip install django-mako-plus

Create a Django project
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Create a Django project, and specify that you want a DMP-style project layout:

::

    python3 -m django_mako_plus dmp_startproject mysite

You can, of course, name your project anything you want, but in the sections below, I'll assume you called your project ``mysite``.

Don't forget to migrate to synchronize your database and create a superuser:

::

    cd mysite
    python3 manage.py migrate
    python3 manage.py createsuperuser


Create a DMP-Style App
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Change to your project directory in the terminal/console, then create a new Django-Mako-Plus app with the following:

::

    python3 manage.py dmp_startapp homepage

**After** the new ``homepage`` app is created, add your new app to the ``INSTALLED_APPS`` list in ``settings.py``:

.. code:: python

    INSTALLED_APPS = [
        ...
        'homepage',
    ]

Congratulations. You're ready to go!

Load it Up!
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Start your web server with the following:

::

    python3 manage.py runserver

If you get a message about unapplied migrations, ignore it for now and continue.

Open your web browser to http://localhost:8000/. You should see a message welcoming you to the homepage app.

If everything is working, `skip ahead to the tutorial <tutorial.html>`_.






Existing Project
---------------------------------

If you already have an existing project that you'd like to integrate DMP into, follow the directions in this section.  First, install Python and ensure you can run ``python3`` (or ``python``) at the command prompt. The framework requires Python 3.4+.

Install Django, Mako, and DMP
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

DMP works with Django 1.9+, including the 2.0 releases.

Install with the python installer:

::

    pip3 install django-mako-plus

Note that on Windows machines, ``pip3`` may need to be replaced with ``pip``:

::

    pip install django-mako-plus


If you need to add DMP to an existing Django project, you have two options:

1. **Convert your project to the DMP structure.** This switches your
   project over to the layout of a DMP-style project.
2. **Keep your existing Django-style structure** with minimal changes.

This section describes Option 1, which gives you the full benefit of the automatic DMP routing and midleware. If you just need to render templates using the Mako language (e.g. Option 2), jump to `Rending Templates the Standard Way: ``render()`` <#rending-templates-the-standard-way-render>`__.

Edit Your ``settings.py`` File:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add ``django_mako_plus`` to the end of your ``INSTALLED_APPS`` list:

.. code:: python

    INSTALLED_APPS = [
        ...
        'django_mako_plus',
    ]

Add ``django_mako_plus.RequestInitMiddleware`` to your ``MIDDLEWARE``
list:

.. code:: python

    MIDDLEWARE = [
        ...
        'django_mako_plus.RequestInitMiddleware',
        ...<commit_msg>small docs change<commit_after>Installation
==============================

This section shows how to install DMP with a new project as well as an existing project.

What kind of project do you have?

.. contents::
    :depth: 3


New Project
-----------------------------

Install Python and ensure you can run ``python3`` (or ``python``) at the command prompt. The framework requires Python 3.4+.

Install Django, Mako, and DMP
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

DMP works with Django 1.9+, including the 2.0 releases.

Install with the python installer:

::

    pip3 install django-mako-plus

(note that on Windows machines, ``pip3`` may need to be replaced with ``pip``)

Create a Django project
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Create a Django project, and specify that you want a DMP-style project layout:

::

    python3 -m django_mako_plus dmp_startproject mysite

You can, of course, name your project anything you want, but in the sections below, I'll assume you called your project ``mysite``.

Don't forget to migrate to synchronize your database and create a superuser:

::

    cd mysite
    python3 manage.py migrate
    python3 manage.py createsuperuser


Create a DMP-Style App
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Change to your project directory in the terminal/console, then create a new Django-Mako-Plus app with the following:

::

    python3 manage.py dmp_startapp homepage

**After** the new ``homepage`` app is created, add your new app to the ``INSTALLED_APPS`` list in ``settings.py``:

.. code:: python

    INSTALLED_APPS = [
        ...
        'homepage',
    ]

Congratulations. You're ready to go!

Load it Up!
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Start your web server with the following:

::

    python3 manage.py runserver

If you get a message about unapplied migrations, ignore it for now and continue.

Open your web browser to http://localhost:8000/. You should see a message welcoming you to the homepage app.

If everything is working, `skip ahead to the tutorial <tutorial.html>`_.






Existing Project
---------------------------------

If you already have an existing project that you'd like to integrate DMP into, follow the directions in this section.  First, install Python and ensure you can run ``python3`` (or ``python``) at the command prompt. The framework requires Python 3.4+.

Install Django, Mako, and DMP
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

DMP works with Django 1.9+, including the 2.0 releases.

Install with the python installer:

::

    pip3 install django-mako-plus

(note that on Windows machines, ``pip3`` may need to be replaced with ``pip``)

If you need to add DMP to an existing Django project, you have two options:

1. **Convert your project to the DMP structure.** This switches your
   project over to the layout of a DMP-style project.
2. **Keep your existing Django-style structure** with minimal changes.

This section describes Option 1, which gives you the full benefit of the automatic DMP routing and midleware. If you just need to render templates using the Mako language (e.g. Option 2), jump to `Rending Templates the Standard Way: ``render()`` <#rending-templates-the-standard-way-render>`__.

Edit Your ``settings.py`` File:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add ``django_mako_plus`` to the end of your ``INSTALLED_APPS`` list:

.. code:: python

    INSTALLED_APPS = [
        ...
        'django_mako_plus',
    ]

Add ``django_mako_plus.RequestInitMiddleware`` to your ``MIDDLEWARE``
list:

.. code:: python

    MIDDLEWARE = [
        ...
        'django_mako_plus.RequestInitMiddleware',
        ...
{'fraction_non_alphanumeric': 0.1575257731958763, 'fraction_numerical': 0.008797250859106528, 'mean_word_length': 3.5418227215980025, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4400827', 'n_tokens_mistral': 2133, 'n_tokens_neox': 1988, 'n_words': 892}