

DefaultRouter ( ) #makes sure that the API endpoints work One key thing to remember is to add rest_framework to the INSTALLED_APPS list in marine/settings.py and change urls.py to from django. We will now incorporate the djangorestframework to the site by downloading and installing it. Up to this point, we have built a working, but plain Django website. You should see a admin page with the Marine list. Open 127.0.0.1:8000/admin and enter the superuser id and password. Start the development server: $ python manage.py runserver We will use the account we created to log into the admin page.
#Android web server with restful apis code
Add the following code after from ntrib import admin.

The feature needs to be activated by editing the admin.py file inside the fishes folder. Django provides a built-in admin page that lets you insert and modify data. If for some reason you do not get prompted to create a superuser, at the command prompt, type: $ python manage.py createsuperuserįollow the instructions to create an administrator’s account. The prompt will ask if you want to create a superuser as this is the first time you have run Django. Django will create authentication tables by default and the empty fishes_fish table in a sqlite3 database. To confirm creating the relevant tables in the default sqlite database, type python manage.py migrate or python manage.py syncdb on older Django versions. BEGIN CREATE TABLE "fishes_fish" ( "id" integer NOT NULL PRIMARY KEY, "name" varchar ( 255 ) NOT NULL, "created" datetime NOT NULL, "active" bool NOT NULL ) COMMIT Run python manage.py sql fishes to see a preview of the database schema SQL that will run when we activate the app. Do this by under INSTALLED_APPS, adding fishes to the list. Now add the fishes app to the marine/settings.py file to register it. You can change the field type by referring to the relevant documentation. This creates a class that exposes the name, created date of the fish and if the data row is active or not. CharField (max_length = 255 )Ĭreated = models. Inside the models.py file, there is the import line from django.db import models. Will result in the following files fishes/ Typing: $ python manage.py startapp fishes A model is the source of data for your app. Next we will build an app (a container) which houses a model (as in Model-View-Controller). If you open the URL you will see a placeholder website. ĭjango version 1.7.4, using settings 'ttings' When successful, you will see: Performing system checks. Which starts the Django development webserver for testing. You can check if everything works as expected by executing: $ python manage.py runserver This is the list of files and folders created. Next, we build the Django project: $ django-admin.py startproject marine This verifies that you have Django installed on your system. All being well you should see version information. You can test your installation by firing up the command line and typing the python command.
#Android web server with restful apis install
If you do not, install Python and Django now. To begin, you will need to have Python v2.7 or later and Django 1.7.4 or later installed. Djangorestframework is built using django (python) specifically for exposing data via the REST framework. We will be using Django (Python MVC framework) and djangorestframework. Using djangorestframework to build a simple REST api
