Django and the Twitter Bootstrap offers the ultimate environment for web development for multiple devices.
Create the project.
[codesyntax lang=”bash”]
django-admin startproject yourAppName
[/codesyntax]
Allow the appropriate access by updating the following in settings.py file.
[codesyntax lang=”bash”]
ALLOWED_HOSTS = ['109.203.114.78', 'localhost', 'archbrooks.us']
[/codesyntax]
Now configure the desired database. Special imports are required for MySQL.
[codesyntax lang=”php”]
import pymysql pymysql.install_as_MySQLdb()
[/codesyntax]
Now include the database configuration parameters.
[codesyntax lang=”php”]
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'YourDB', 'USER' : 'YourUser', 'PASSWORD' : 'Password', 'HOSTS' : '', 'PORT' : '', } }
[/codesyntax]
At this point I would start the server to check for errors.
[codesyntax lang=”php”]
python manage.py runserver 0.0.0.0:8000
[/codesyntax]
The next step is to install the Twitter Bootstrap.
[codesyntax lang=”php”]
pip install django-twitter-bootstrap
[/codesyntax]
The following is generated after sucessful install of bootstrap.
[codesyntax lang=”php”]
Enter root@server:~/django/nws# pip install django-twitter-bootstrap Collecting django-twitter-bootstrap Downloading django-twitter-bootstrap-3.3.0.tar.gz (156kB) 100% |████████████████████████████████| 163kB -276578bytes/s Building wheels for collected packages: django-twitter-bootstrap Running setup.py bdist_wheel for django-twitter-bootstrap ... done Stored in directory: /root/.cache/pip/wheels/7b/b2/e7/93eebb9195c2f80c83ce543768b99629c3da5ec89fb81bfb1b Successfully built django-twitter-bootstrap Installing collected packages: django-twitter-bootstrap Successfully installed django-twitter-bootstrap-3.3.0 code here
[/codesyntax]
Now create the first application of the site.
[codesyntax lang=”php”]
django-admin startapp myapp
[/codesyntax]
At this point I would start the server to check for errors.
[codesyntax lang=”php”]
python manage.py runserver 0.0.0.0:8000
[/codesyntax]
If no errors were reported you are now ready to activate the first page of your site.
Modify the urls.py file for the application to reflect the following:
[codesyntax lang=”php”]
from django.conf.urls import include, url from django.contrib import admin from mws import views urlpatterns = [ url(r'^$', views.index, name='index'), url(r'^admin/', include(admin.site.urls)), ]
[/codesyntax]
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.