Install and Setup Django in Pythonista3 (iOS app)

How to Set up Django in Pythonista3, iOS app for iPhone and iPad:

First, make sure you have StaSH installed in your Pythonista3 app.

In StaSH execute following command:

pip install Django==1.11.6

Select version “1.11.6” or Long Term Support version available. See Djangoproject.com website for the latest LTS version available. (Comment added on Jun 12, 2021) you may be able to execute “pip install django” and the version 3.2.4 will be installed. Specifya version only when necessary.

Quit and launch Pythonista <– This is one of most important steps when you make changes to Pythonista3!

Create an application (in stash)

django-admin.py startproject mysite

Quit and launch Pythonista

Open /mysite/manage.py
Go to console and run:

import sys
sys.path

Locate and copy a line like below where “…” is device specific.

/private/var/mobile/.../Documents/mysite

Go back to the edit page (manage.py).
Add a line like below under “import sys” — replace “PASTE HERE” with the line copied in the prev step. (Comment added on Jun 12, 2021) Removed unnecessary “=” after “append”.

sys.path.append(“PASTE HERE”)

So, it will look something like below:

sys.path.append("/private/var/mobile/Containers/Shared/AppGroup/C1F57ABC-DDDD-EEEE-FFFF-B0B0E0B0B0E7/Pythonista3/Documents/mysite/")

Quit and launch Pythonista

Open /mysite/manage.py, tap and hold the play (run) button and enter “runserver --noreload” as an argument. You may need to copy and paste “--noreload” without double-quotes.


If you see unforseen errors, quit Pythonista and relaunch then follow the steps again.
If successful, you see something like below in the Console:

Performing system checks...

System check identified no issues (0 silenced).

You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
November 03, 2017 - 20:46:35
Django version 1.11.6, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Now, open http://127.0.0.1:8000/ in Safari or any other web browser.

Version 3.2.4

If you see the “Congratulations!” page, your setup is complete, and it’s time to move forward to programing your own site/app.
Make sure you quit and relaunch Pythonista to properly apply your changes to your Django sites/apps.

StaSH log (installation of Django 1.11.6):

[~/Documents]$ pip list
[~/Documents]$
[~/Documents]$
[~/Documents]$ pip install django
Querying PyPI ...
Error: Source distribution not available for Django: 2.0b1
[~/Documents]$ pip install Django==1.11.6
Querying PyPI ...
Downloading package ...
Opening: https://pypi.python.org/packages/13/26/f3841e00663027ba7cf7ce7ba2cabb682a83cf0629bef013d70bebefa69d/Django-1.11.6.tar.gz
Save as: /private/var/mobile/Containers/Data/Application/20C8FA54-EEEE-FFFF-8888-3BACC5555555/tmp//Django-1.11.6.tar.gz (7874450 bytes)
7874450 [100.00%]
Extracting archive file ...
Archive extracted.
Running setup file ...
Handling commandline script: django/bin/django-admin.py
Package installed: Django
Dependency available in Pythonista bundle : pytz
[~/Documents]$
[~/Documents]$
[~/Documents]$ which django
[~/Documents]$ pip list
Django (2.0b1) - A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
[~/Documents]$

11 Replies to “Install and Setup Django in Pythonista3 (iOS app)”

  1. I get errors: “Operation not permitted”(ios 12 not unlocked)
    or
    CommandError: “-noreload” is not a valid port number or address:port pair
    or unrecognized arguments: -noreload

    1. I would suggest double-dash “–” instead of a single “-“.
      Also quit and relaunch Pythonista.

  2. This is great, thanks! I’m getting the following when I run “runserver –noreload”

    Traceback (most recent call last):
    File “/private/var/mobile/Containers/Shared/AppGroup/5F13168C-56BD-4FA8-8611-EA705AEB7338/Pythonista3/Documents/mysite/manage.py”, line 5, in
    sys.path.append=(“/private/var/mobile/Containers/Shared/AppGroup/5F13168C-56BD-4FA8-8611-EA705AEB7338/Pythonista3/Documents/mysite”)
    AttributeError: ‘list’ object attribute ‘append’ is read-only

    1. Hey Jeff,

      You might have already figured it out but…

      Remove “=” from the below line 5 in your manage.py, and it should work.

      sys.path.append=(“/private/var/mobile/Containers/Shared/AppGroup/5F13168C-56BD-4FA8-8611-EA705AEB7338/Pythonista3/Documents/mysite”)

  3. It’s amazing to see Django on iPad. However, I installed stash and django (latest version 3.2.4) but I cannot force it to run.

    I get:
    CommandError: “–noreload” is not a valid port number or address:port pair.

    1. I found an error in my post so just fixed it. Then followed the steps from scratch and could start the server. You might want to try again after uninstalling Django. Make sure you quit and relaunch Django before runserver –noreload (double dashes before “noreload”).

  4. On StaSh when running Django-admin.py startproject my site get syntax error “invalid syntax (Django-admin.py, Line 3). How to correct?

  5. Correction to my last mail
    mysite not my site
    I have also used “- -“ and not work

    1. Hey George,
      First thing you should try is quit Pythonista 3, relaunch and execute the command.
      You will need a few quit-relaunch’es until your project starts working.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© Peddals.com