Introduction to Django

Slides:



Advertisements
Similar presentations
© 2012 Entrinsik, Inc. Informer Administration Exploring the system menu and functions PRESENTER: Jason Vorenkamp| Informer Software Engineer| March 2012.
Advertisements

FIRST SESSION - XAMPP Jeongmin Lee.  Jeongmin Lee  CS  PHD  Machine Learning, AI  Web System Development.
LIS654lecture 3 omeka installation and system overview start Thomas Krichel
George Blank University Lecturer. Creating A Web Site at NJIT Professor Blank.
Chapter Apache Installation in Linux- Mandrake. Acknowledgment The following information has been obtained directly from
CP476 Internet Computing Browser and Web Server 1 Web Browsers A client software program that allows you to access and view Web pages on the Internet –Examples.
Presented by Mina Haratiannezhadi 1.  publishing, editing and modifying content  maintenance  central interface  manage workflows 2.
APACHE SERVER By Innovationframes.com »
Installing Active Directory on Windows Server 2008 R2 Installing Active Directory on a fresh Windows Server 2008 R2 machine in a home network. These instructions.
Linux Operations and Administration
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
CONFIGURING WINDOWS SERVER MIS 424 Professor Sandvig.
The DSpace Course Module – DSpace Installation. Module objectives  By the end of this module you will:  Understand the platforms DSpace can be hosted.
Microsoft Windows 2003 Server. Client/Server Environment Many client computers connect to a server.
Web Server Configuration Alokes Chattopadhyay Computer & Informatics Centre IIT Kharagpur.
Chapter 1: Introduction to Web
E-Commerce: Introduction to Web Development 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics What is a Web.
HTML Hyper Text Markup Language A simple introduction.
FTP Server and FTP Commands By Nanda Ganesan, Ph.D. © Nanda Ganesan, All Rights Reserved.
Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Chapter.
Turning Windows 7 into a Web Server Ch 28. Understanding Internet Information Services.
MySQL Getting Started BCIS 3680 Enterprise Programming.
17 Establishing Dial-up Connection to the Internet Using Windows 9x 1.Install and configure the modem 2.Configure Dial-Up Adapter 3.Configure Dial-Up Networking.
Lab 8 Overview Apache Web Server. SCRIPTS Linux Tricks.
Day 15 Apache. Being a web server Once your system is correctly connected to the network, you could be a web server. –When you go to a web site such as.
Tomcat Setup BCIS 3680 Enterprise Programming. One-Click Tomcat Setup 2  This semester we’ll try to set up Tomcat with a PowerShell script.  Preparation.
Your current Moodle 1.9 Minimum Requirements Ability to do a TEST RUN! Upgrading Moodle to Version 2 By Ramzan Jabbar Doncaster College for the Deaf By.
Installing a Moodle Test Site The painless and easy way.
Joomla Awdhesh Kumar Singsys Pte Ltd. What is Joomla? Joomla is an award-winning content management system (CMS), which enables you to build Web sites.
Building Your Own Website Using:. Install & configure LAMP. Download WordPress and run it as a local website on your Raspberry Pi. Configure WordPress.
Apache Web Server v. 2.2 Reference Manual Chapter 2 Starting Apache.
Basic Web Design UVICELL Week 4 Templates and site management Week 4 Templates and site management.
9/21/04 James Gallagher Server Installation and Testing: Hands-on ● Install the CGI server with the HDF and FreeForm handlers ● Link data so the server.
L.A.M.P. İlker Korkmaz & Kaya Oğuz CS 350. Why cover a lecture on LAMP? ● Job Opportunities – There are many hosting companies offering LAMP as a web.
WampServer 2 Installation WAMP is a solution stack of open source programs used together to run dynamic Web sites or servers Most common expansion:  Windows,
COMP3121 E-Commerce Technologies Richard Henson University of Worcester December 2009.
4.01 How Web Pages Work.
2nd year Computer Science & Engineer
4.01 How Web Pages Work.
beas group AG Beas sql guide Martin Heigl CTO
bitcurator-access-webtools Quick Start Guide
4.01 How Web Pages Work.
Dreamweaver – Setting up a Site and Page Layouts
Development Environment
Landscape Institute Introducing the new Branch Websites
Data Virtualization Tutorial… OAuth Example using Google Sheets
CNIT131 Internet Basics & Beginning HTML
mysql and mysql workbench
Introduction to Programming the WWW I
PHP Training at GoLogica in Bangalore
Bomgar Remote support software
Files, folders, directories, URLs, and IP addresses
Dynamic DNS support for EGI Federated cloud
INSTALLING AND SETTING UP APACHE2 IN A LINUX ENVIRONMENT
DHCP, DNS, Client Connection, Assignment 1 1.3
Planning a Group Policy Management and Implementation Strategy
Building Web Applications
Getting Started: Amazon AWS Account Creation
LING 408/508: Computational Techniques for Linguists
OPS235: Week 1 Installing Linux ( Lab1: Investigations 1-4)
MIS2502: Data Analytics MySQL and SQL Workbench
APACHE WEB SERVER.
4.01 How Web Pages Work.
Web Servers (IIS and Apache)
4.01 How Web Pages Work.
Web Application Development Using PHP
How to install and manage exchange server 2010 OP Saklani.
Presentation transcript:

Introduction to Django Lecture 20 Introduction to Django

Install Apache Web Server Apache Web Server is the most widely used web server Open source Usually running in Linux or UNIX, but there are versions for Windows and OSX Install it on your Digital Ocean VM. You do not need it on your local machine, since Django includes a lightweight server for development. To install the basic functionality of Apache in Fedora: sudo dnf install httpd You can also look up how to install additional functionality to support servlets, etc. to start up: sudo systemctl start httpd.service or sudo service httpd start If the server goes down during use, and after every time you edit the configuration files, use sudo systemctl restart httpd.service 2

Install Apache Web Server Verify that the install and startup worked by entering your VM's ip address in a browser on your client machine. You should see this test page: 3

Install Apache Web Server Create a home page in Apache: Navigate to /var/www/html. This will require sudo. This directory is the root of your website; create any additional directory structure you need within html. Use a separate directory *inside html* for css. Recall that web servers automatically serve index.html or index.htm if no file name is provided. The file owner for index.html should be root. Use sudo if necessary to accomplish this. This home page does not need to contain anything except a simple message. The point is simply to make sure Apache is working correctly. Note that the URL for your home page will *not* include the /var/www/html. The server is set up to "map" urls into this directory. If your ip address is 123.456.789.12, the URL of your index.html is just http://123.456.789.12 See Digital Ocean's documentation if you want to get a domain name and/or use TLS (SSL) (both very cheap) 4

Install Postgres and psycopg2 For Windows and OSX, follow the directions on the Django tutorial site. For Fedora: sudo dnf install postgresql sudo dnf install postgresql-server sudo postgresql-setup –initdb sudo dnf install postgresql-devel? sudo postgresql-setup --initdb psycopg2 is an adapter that connects Python to Postgres: sudo dnf install python3-psycopg2 start postgres server in Fedora: sudo systemctl start postgresql 5

Use Postgres, not sqlite The Django sample application instructions assume you will use sqlite, but when you deploy the app to Digital Ocean, you will need to use Postgres. I suggest you create the sample app using Postgres in the first place. When you deploy the app to DO, you will need to create the user and set the password top match the settings in settings.py. You will also need to set db permissions. There are instructions online at: https://www.postgresql.org/message-id/4D958A35.8030501@hogranch.com Start Postgres as user postgres the first time like this: sudo -u postgres psql change postgres' password: alter user postgres password [new password here, in single quotes]; create username and password for the user: create user [username here] createdb password [password here, in single quotes]; create database [username] owner [username] \q quits portgres \h gets you a postgres help menu This link has information on Postgres configuration with Fedora: https://fedoraproject.org/wiki/PostgreSQL 6

Django Framework for web programming using Python Automates many common tasks Named after jazz musician Django Reinhardt Pinterest, Instagram, and many other complex web apps use Django. Originally created for the web site of a newspaper, the Lawrence Journal-World. Several recent Senior Design projects have used Django Django Reinhardt

Object-Relational Mapping Web applications typically use OOP Data is typically stored in relational databases If a data value in an object is non-scalar (say, it is a list or array), or if the value is of some type that itself has non-scalar fields, the relationship between the class and the database tables is complex. Consider a Student object with a list of courses, each of which has one or more instructors who may also teach other courses. We will need several cross- reference tables in the DB. OO Inheritance makes database design even more difficult Like many other web programming frameworks, Django provides automatic Object- Relational Mapping

Automatic CRUD Most software applications involve creating and processing data CRUD = Create, Read, Update, Delete Django was developed for a newspaper website, in which some users provided data and others consumed it Django includes an automatically generated administrative user interface for CRUD functions

Model-View-Template Most web frameworks use Model-View-Controller pattern Django is not really very different, but it uses different nomenclature Data and interaction with the DB = Model Application logic to manipulate data = View (this is an unusual use of the word view!) Generic html pages that receive and display specific data at runtime = Template

Django Assuming you use a Windows or OSX computer for your homework, you may approach this project in either of two ways: 1) Develop the project in your native operating system 2) Use VirtualBox to run Fedora on your own machine Either way, use the Django development server on your own computer. You will have to redeploy the project to Apache on Digital Ocean when you are finished. Do not assume that will go smoothly. Use Django 1.9 on your home machine, since that is the version Fedora 25 supports. You can try to install a later version of Django on Fedora, but if you do, start very early Most of the instructions that follow concern Fedora. The Django documentation contains instructions for installing Django and starting a project in Windows at https://docs.djangoproject.com/en/1.9/topics/install/ If you are worried about the security warning, you can try to get Django 1.11 working on Fedora, but I have not tried this yet. If you write the application using 1.11 and try to deploy in 1.9, you will certainly run into undocumented problems. If you use OSX, go slow and think about ways the instructions may not apply to OSX. Installation using Terminal is probably reasonably similar to the Fedora instructions here. It is undoubtedly also possible to do most of it using the GUI. There are many sets of instructions online. I can't vouch for any of them. Make sure any instructions you try are for Python 3 and Django 1.9. 11

Django The online instructions are sometimes not quite right for Fedora. One very important example: when the instructions say to type python, type python3. Install Django for Python 3: sudo dnf install python3-django I did not use a virtualenv, but you may follow the instructions to do so 12

Start a Django Project Stop! Read this before you create the project! The official instructions for the Django demo project are at https://docs.djangoproject.com/en/1.9/intro/tutorial01/ Read the instructions in parallel to these slides, and go slow. Always check the slides before you follow an instruction from the documentation. Also, always read ahead to the end of a page in the instructions before you do anything. On Digital Ocean or any other machine where you plan to run a webserver, don't put your project inside /var/www. That is where Apache puts web documents by default. Since this part of the file system can be accessed directly by the server, it would be easier for unauthorized users to read your Python code if you put it here. Put it someplace else. The Django documentation suggests /home/mycode 13

Start a Django Project If you are developing in Windows or OSX, you will not need to start a project in Fedora, since you will instead be uploading a project you created in your native OS. command to create project in Fedora: python3-django-admin startproject mysite command to run the Django development server: python3 manage.py runserver 14

Apache and mod_wsgi When you are are ready to deploy to D.O., upload your code using sftp. If you are ambitious about this, you can find instructions to use git instead. mod_wsgi is an extension to Apache that supports Python. You will need to install it on the Digital Ocean VM, but not on your homework computer sudo dnf install python3-mod_wsgi See the installation instructions at https://docs.djangoproject.com/en/1.11/topics/install/ and the deployment instructions at https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/modwsgi/ Ignore the recommendation to use an additional server for static and media files. You may also need to add the ip address to Allowed_Hosts in settings.py You can find httpd.conf this way: sudo find / -name httpd.conf don't edit the copy in tmpfiles; there is probably one inside /etc When you edit httpd.conf, the changes take effect only after sudo systemctl restart httpd 15

Apache and mod_wsgi You will need to migrate the database again on DO. See the Django documentation 16

Django SELinux is an additional layer of security functionality included by many Linux distros, including Fedora. allow access to files and directories like this: sudo chcon -v --type=httpd_sys_content_t wsgi.py do this for each of the directories starting with mysite and each of the .py files. 17

Serving static files In Django terminology, css, background images, media files, etc, are static files This link contains instructions for serving them in your application. Follow the instructions for using the same server you use for the rest of the app. https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/modwsgi/#serving-files You can write your own css if you'd like to, but you can also just copy the ones used in the sample app. They are probably in /usr/lib/python3.5/site-packages/django/contrib/admin/static/admin/css/ 18

What the heck is wrong? Read error logs early and often! Find Apache error logs: sudo find / -name error_log read the log: sudo cat /var/log/httpd/error_log (is that is the right path) read just the last 50 lines of the error log: sudo cat /var/log/httpd/error_log | tail -n 50 Postgres error logs will be in files in a directory called pg_log. They will probably be in /var/lib/pgsql/data/pg_log/ 19