Django-Mako-Plus Documentation

Size: px
Start display at page:

Download "Django-Mako-Plus Documentation"

Transcription

1 Django-Mako-Plus Documentation Release 4.1 Conan C. Albrecht Feb 14, 2018

2

3 Contents 1 Code 3 2 Features 5 3 Quick Start 7 4 Contents About DMP Upgrade Notes Installation Tutorial Topics Compatability 75 i

4 ii

5 Show Me the Code: 1. Django Syntax vs. DMP Syntax 2. Simple Template 3. Basic View (.py file) 4. Ajax Example Routing Django to Mako since 2013 Contents 1

6 2 Contents

7 CHAPTER 1 Code 3

8 4 Chapter 1. Code

9 CHAPTER 2 Features DMP adds convention-over-configuration to Django: Uses standard Python in templates; no more weak-sauce Django templating. Calls any view function by convention instead of listing every. single. page. in urls.py. Converts parameters in the URL and loads model objects by convention. Automatically links.js and.css in your HTML documents by convention. Automatically sets context variables in the Javascript namespace. Provides Django-style signals. Extends Django s redirecting with exception-based redirecting. Supports language translations, class-based views, and collection of static files. Includes a comprehensive test suite. DMP doesn t replace Django; the standard router and template engine can be used alongside it. 5

10 6 Chapter 2. Features

11 CHAPTER 3 Quick Start # install django, mako, and DMP pip3 install django-mako-plus # create a new project with a 'homepage' app python3 -m django startproject --template= plus/master/project_template.zip mysite cd mysite python3 manage.py startapp --template= master/app_template.zip --extension=py,htm,html homepage # open mysite/settings.py and append 'homepage' to the INSTALLED_APPS list INSTALLED_APPS = [... 'homepage', ] # run initial migrations and run the server python3 manage.py migrate python3 manage.py runserver # Open a browser to Note that on Windows, python3 is python and pip3 is pip. Python 3+ is required. 7

12 8 Chapter 3. Quick Start

13 CHAPTER 4 Contents 4.1 About DMP Contents About DMP Frequently Asked Questions * Where Is DMP Used? * What s wrong with Django s built-in template language? * Why Mako instead Django or Jinja2? * Can I use DMP with regular Django apps? Comparison with Django Django-Mako-Plus makes creating web sites faster through convention-over-configuration in the Django framework. It integrates the Mako templating engine, which looks much more like Python than the standard templating language. Yet it still conforms to the Django API and plugs in as a standard engine. DMP boasts the following advantages: 1. It uses the Mako templating engine rather than the weaker Django templating engine. Why would I want to learn a whole new language for templating when Mako uses my favorite language: Python? 2. It enables calling views and html pages by convention rather than specific entries in urls.py. Any.html file on your site can be called without new entries in urls.py for every. single. new. page. Doesn t Python favor convention over configuration? 3. DMP introduces the idea of URL parameters with automatic type conversion. These allow you to embed parameters in urls, Django style meaning you can use pretty URLs like without explicit entries in urls.py and without the need for traditional (i.e. ulgy)?first=abc&second=def&third=123 syntax. 9

14 4. It includes CSS and JS files with the same name as the current template automatically. This means that mypage.css and mypage.js get linked in mypage.html automatically. Plus, DMP allows sending context values from your Python view code right into your Javascript namespace, without any significant hacks. 5. DMP can compile your preprocessor files, such as.scss,.less, or even Transcrypt.py Frequently Asked Questions Where Is DMP Used? This app was developed at MyEducator.com, primarily by Dr. Conan C. Albrecht. Please me if you find errors with this tutorial or have suggestions/fixes. In addition to several production web sites, I use the framework in my Django classes at BYU students use the framework each year, and many have taken it to their companies upon graduation. At this point, the framework is quite mature and robust. It is fast and stable. I ve been told by some that DMP has a lot in common with Rails. When I developed DMP, I had never used RoR, but good ideas are good ideas wherever they are found, right? :) What s wrong with Django s built-in template language? Django comes with its own template system, but it s fairly weak (by design). Mako, on the other hand, is a fantastic template system that allows full Python code within HTML pages. The primary reason Django doesn t allow full Python in its templates is the designers want to encourage you and I to keep template logic simple. I fully agree with this philosophy. I just don t agree with the forced part of this philosophy. The Python way is rather to give freedom to the developer but train in the correct way of doing things. Even though I fully like Python in my templates, I still keep them fairly simple. Views are where your logic goes. Why Mako instead Django or Jinja2? Python has several mature, excellent templating languages. Both Django and Jinja2 are fairly recent yet mature systems. Both are screaming fast. Mako itself is very stable, both in terms of lack of bugs and in completed feature set. Today, the Mako API almost never changes because it does exactly what it needs to do and does it well. This make it an excellent candidate for server use. The short answer is I liked Mako s approach the best. It felt the most Pythonic to me. Jinja2 may feel more like Django s built-in template system, but Mako won out because it looked more like Python and the point of DMP is to include Python in templates. Can I use DMP with regular Django apps? Yes. DMP plugs in as a regular templating engine per the standard Django API. You can use both DMP and regular Django simultaneously in the same project. When you include DMP s urls.py module in your project, patterns for each DMP-enabled app in your project are linked to our convention-based router. Other apps won t match these patterns, so other apps route the normal Django way. This means third-party apps work just fine with DMP. Note also that other apps likely use Django s built-in templating system rather than DMP s Mako templating system. The two templating systems work fine side by side, so other apps should render fine the normal Django way and your custom apps will render fine with Mako. 10 Chapter 4. Contents

15 Further, if you temporarily need to switch to Django templating syntax, you can do that with ease. This allows the use of Django-style tags and syntax right within your Mako code. No new files needed Comparison with Django If you have read through the Django Tutorial, you ve seen examples for templating in Django. While the rest of Django, such as models, settings, migrations, etc., is the same with or without DMP, the way you do templates will obviously change with DMP. The following examples should help you understand the different between two template systems. Note that, for the most part, the right column uses standard Python syntax. That s why Mako rocks. Django Output the value of the question variable: DMP (Mako) {{ question }} ${ question } Call a method on the User object: {{ user.get_full_name }} ${ user.get_full_name() } Call a method with parameters on the User object: Requires a custom tag. ${ user.has_perm( app.get_main_view ) } Iterate through a relationship: <ul> {% for choice in question.choice_set.all %} <li>{{ choice.choice_text }}</li> {% endfor %} </ul> <ul> %for choice in question.choice_set.all(): <li>${ choice.choice_text }</li> %endfor </ul> Set a variable: {% with name= Sam %} <% name = Sam %> Format a date: {{ value date: D d M Y }} ${ value.strftime( %D %d %M %Y ) } Join a list: {{ mylist join:, }} ${,.join(mylist) } Use the /static prefix: {% load static %} <img src= {% get_static_prefix %}images/hi.jpg /> Call a Python method: <img src= ${ STATIC_ROOT }images/hi.jpg /> Continued on next page 4.1. About DMP 11

16 Table 4.1 continued from previous page Django DMP (Mako) Requires a custom tag, unless a built-in tag provides the Any Python method can be called: <%! import random behavior. %> ${ random.randint(1, 10) } Print a Django form: <form action= /your-name/ method= post > {% csrf_token %} {{ form }} <input type= submit value= Submit /> </form> Output a default if empty: {{ value default: nothing }} Run arbitrary Python (keep it simple, Tex!): <form action= /your-name/ method= post > ${ csrf_input } ${ form } <input type= submit value= Submit /> </form> Use a boolean: ${ value or nothing } or use a Python if statement: ${ value if value is not None else nothing } Requires a custom tag Inherit another template: <% %> i = 1 while i < 10: context.write( <p>testing {0}</p>.format(i)) i += 1 {% extends base.html %} <%inherit file= base.htm /> Override a block: {% block title %}My amazing blog{% endblock %} <%block name= title >My amazing blog</%block> Link to a CSS file: Place in template: <link rel= stylesheet type= text/css href=... > Perform per-request logic in JS files: Difficult, young padwan... very difficult. Simply name the.css/.js file the same name as your.html template. DMP will include the link automatically. Wrap context keys with jscontext(), and DMP will make the variable available in your JS file. 4.2 Upgrade Notes This document contains upgrade notes for those already using DMP. We started the document at version February, 2018 Most changes can be summarized in the DMP settings.py options. We recommend comparing your settings.py file against the current template (see file project_template/project_name/settings.py-tpl on GitHub). This will likely signal 12 Chapter 4. Contents

17 all the changes you may need to make. 1. The biggest change is the variables DMP attaches to the request have been moved to an object, available as request.dmp. This causes less namespace pollution of the request and allows easier changes going forward. The following are the old to new adjustments you may need. We recommend moving from urlparams to automatic view parameter conversion, although this is likely a significant change (there are no plans to remove urlparams, so this isn t required). Old New (DMP 4.4) request.dmp_router_app request.dmp.app request.dmp_router_page request.dmp.page request.dmp_router_function request.dmp.function request.dmp_router_module request.dmp.module request.dmp_router_class request.dmp.class_obj request._dmp_router_callable request.dmp.function_obj request.urlparams request.dmp.urlparams request.dmp_render request.dmp.render request.dmp_render_to_string request.dmp.render_to_string Important: As noted in the table above, search your codebase for request.dmp_render and replace with request.dmp.render. 2. Static files (CSS/JS): MakoCssProvider, MakoJsProvider, link_css, link_js, link_template_css, link_template_js are removed. Instad, use ${ django_mako_plus.links() } once in the <head> section of your base page. 3. RedirectException: Optional parameters permanent and as_javascript are removed. Use the subclasses by these names instead. 4. SCSS Compiling: The entire sass.py file is removed, including functions check_template_scss, compile_scss_file, compile_scssm_file. Instead, use the Sass compile provider. See providers for more information. 5. The parameter keys in urls.py has changed. You only need to adjust your urls.py if you have custom patterns. For those doing it the normal way (including DMP s urls.py), no change is necessary. Old New (DMP 4.4) dmp_router_app dmp_app dmp_router_page dmp_page dmp_router_function dmp_function urlparams dmp_urlparams 6. Rendering: render_to_string_shortcut_deprecated and render_to_response_shortcut_deprecated are removed, but this shouldn t affect anyone because they are internal function November, 2017 tl;dr for existing projects: 1. Add dmp-common.js to your site s base template (add above any DMP calls). 2. Search for django_mako_plus.link_css and change to django_mako_plus.links. 3. Search for django_mako_plus.link_js and simply remove. 4. Search for django_mako_plus.link_template_css and change to django_mako_plus. template_links. 5. Search for django_mako_plus.link_template_js and remove Upgrade Notes 13

18 6. (optional) Change deprecated.cssm files to.css and.jsm files to.js. This one may take some work. Be sure to read the docs on what needs to be done. We added provider classes, which creates a customizable system for linking static files. Default settings for the providers will handle everything for you, but note that you can add CONTENT_PROVIDERS to your settings file to customize how links are created in templates. DMP now requires inclusion of dmp-common.js in your base template(s). This is included in the base template of new projects, but existing projects need to link to the file. See the installation guide for more info. link_css and link_js functions are deprecated but still work for now. Your base template should now have a single call to django_mako_plus.links(self) in the <head> section. To switch over, simply replace link_css with links and delete the reference to link_js. Both style and script links are returned by the new function because best practices no longer recommend placing scripts at the end of your page (async/defer in modern browsers make it unnecessary). In similar fashion, link_template_css and link_template_js is now one call to template_links. *.cssm files are deprecated but still work for now. Few users seemed to use this. If you are using them, move the dynamic parts to your templates and convert to a normal css file. *.jsm files are deprecated but still work for now. These were of great use to many, but jscontext gives a new, improved way to do dynamic JS. Convert all.jsm files to regular.js files, and follow the pattern given in the tutorial. The new method still allows you to easily send variables to your JS but doesn t need any rendering. You ll need to convert code in your JS from if (${ somebool }) to if (context.somebool). Note that the Mako codes are gone, and the new code is pure JS that uses a context dictionary that exists in the JS namespace. Compilation of Scss has been moved to a provider class, and a new provider for Less is now available. In fact, the CompileProvider can compile any type of file (using the settings in CONTENT_PROVIDERS). Check out the Transcrypt example in the topic on CSS and JS. 4.3 Installation The easiest way to install DMP is by creating a new project. 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 Installation New Project * Install Django, Mako, and DMP * Create a Django project * Create a DMP-Style App * Load it Up! Existing Project * Install Django, Mako, and DMP * Create a DMP-Style App * Load it Up! 14 Chapter 4. Contents

19 * Not a designated DMP app? Subdirectory: /mysite/ New Project Install Python and ensure you can run python3 (or python) at the command prompt. The framework requires Python Install Django, Mako, and DMP DMP 3 works with Django 1.9+ and Mako It will support Django 2.0 when it is released. 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 startproject --template= plus/master/project_template.zip mysite In addition to giving you the DMP project directories, this command automatically adds the required pieces to your settings.py and urls.py files. 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 startapp --template= master/app_template.zip --extension=py,htm,html homepage After the new homepage app is created, add your new app to the INSTALLED_APPS list in settings.py: INSTALLED_APPS = [... 'homepage', ] 4.3. Installation 15

20 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 You should see a message welcoming you to the homepage app. If everything is working, skip ahead to the tutorial Existing Project Install Python and ensure you can run python3 (or python) at the command prompt. The framework requires Python Install Django, Mako, and DMP DMP 3 works with Django 1.9+ and Mako It will support Django 2.0 when it is released. 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 router and midleware. If you need Option 2, jump to Rending Templates the Standard Way: render() <#rending-templates-the-standard-wayrender>. Edit Your settings.py File: Add django_mako_plus to the end of your INSTALLED_APPS list: INSTALLED_APPS = [... 'django_mako_plus', ] Add django_mako_plus.requestinitmiddleware to your MIDDLEWARE list: 16 Chapter 4. Contents

21 MIDDLEWARE = [... 'django_mako_plus.requestinitmiddleware',... ] Add a logger to help you debug (optional but highly recommended!): DEBUG_PROPAGATE_EXCEPTIONS = DEBUG # SECURITY WARNING: never set this True on a live site LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'dmp_simple': { 'format': '%(levelname)s::dmp %(message)s' }, }, 'handlers': { 'dmp_console':{ 'level':'debug', 'class':'logging.streamhandler', 'formatter': 'dmp_simple' }, }, 'loggers': { 'django_mako_plus': { 'handlers': ['dmp_console'], 'level': 'DEBUG', 'propagate': False, }, }, } Add the Django-Mako-Plus engine to the TEMPLATES list. Note that a standard Django project already has the TEMPLATES = line. TEMPLATES = [ { 'NAME': 'django_mako_plus', 'BACKEND': 'django_mako_plus.makotemplates', 'OPTIONS': { # functions to automatically add variables to the params/context before templates are rendered 'CONTEXT_PROCESSORS': [ 'django.template.context_processors.static', # adds "STATIC_URL" from settings.py 'django.template.context_processors.debug', # adds debug and sql_queries 'django.template.context_processors.request', # adds "request" object 'django.contrib.auth.context_processors.auth', # adds "user" and "perms" objects 'django.contrib.messages.context_processors.messages', # adds messages from the messages framework "settings" dictionary ], 'django_mako_plus.context_processors.settings', # adds 4.3. Installation 17

22 # identifies where the Mako template cache will be stored, relative to each template directory 'TEMPLATES_CACHE_DIR': '.cached_templates', # the default app and page to render in Mako when the url is too short # if None (no default app), DMP will not capture short URLs 'DEFAULT_APP': 'homepage', 'DEFAULT_PAGE': 'index', # the default encoding of template files 'DEFAULT_TEMPLATE_ENCODING': 'utf-8', # imports for every template 'DEFAULT_TEMPLATE_IMPORTS': [ # import DMP (required) 'import django_mako_plus', # uncomment this next line to enable alternative syntax blocks within your Mako templates # 'from django_mako_plus import django_syntax, jinja2_syntax, alternate_syntax templates ], # the next two lines are just examples of including common imports in # 'from datetime import datetime', # 'import os, os.path, re, json', # whether to send the custom DMP signals -- set to False for a slight speed-up in router processing # determines whether DMP will send its custom signals during the process 'SIGNALS': False, ] }, }, # see the DMP online tutorial for information about this setting # it can normally be empty 'TEMPLATES_DIRS': [ # '/var/somewhere/templates/', ], Add the following to serve your static files. Note that a standard Django project already has the first STATIC_URL = line. STATIC_URL = '/static/' # you probably already have this STATICFILES_DIRS = ( # SECURITY WARNING: this next line must be commented out at deployment BASE_DIR, ) STATIC_ROOT = os.path.join(base_dir, 'static') Clean out all the cached template files. This should be done anytime you make a DMP change in settings.py: python manage.py dmp_cleanup 18 Chapter 4. Contents

23 Enable the Django-Mako-Plus Router Add the Django-Mako-Plus router in your urls.py file (the default admin is also included here for completeness). from django.conf.urls import url, include urlpatterns = [ # urls for any third-party apps go here ] # adds all DMP-enabled apps url('', include('django_mako_plus.urls')), 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 startapp --template= master/app_template.zip --extension=py,htm,html homepage After the new homepage app is created, add your new app to the INSTALLED_APPS list in settings.py: 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 You should see a message welcoming you to the homepage app. If everything is working, skip ahead to the tutorial. Not a designated DMP app? If DMP tells you that an app you re trying to access is not a designated DMP app, you missed something above. Rather than go above and trying again, go on to the next section on converting existing apps for a summary of everything needed to make a valid DMP app. You re likely missing something in this list, and by going through this next section, you ll ensure all the needed pieces are in place. I ll bet you didn t set the DJANGO_MAKO_PLUS = True part in your app s init file. Another possible reason is you didn t list homepage as one of your INSTALLED_APPS as described above Installation 19

24 4.3.3 Subdirectory: /mysite/ This section is for those that need Django is a subdirectory, such as /mysite. If your Django installation is at the root of your domain, skip this section. In other words, suppose your Django site isn t the only thing on your server. Instead of the normal url pattern, / your Django installation is at All apps are contained within this mysite/ directory. This is accomplished in the normal Django way. Adjust your urls.py file to include the prefix: url('^mysite/', include('django_mako_plus.urls')), 4.4 Tutorial These five tutorial pages are the best way to learn about DMP. Assuming you have gone through the installation instructions, this is your jumping off point T1: Meet DMP Contents T1: Meet DMP For the Impatient Your New App Goodbye, urls.py I ll assume you ve just installed Django-Mako-Plus according to the installation instructions. You should have a dmp_test project directory that contains a homepage app. I ll further assume you know how to open a terminal/console and cd to the dmp_test directory. Most of the commands below are typed into the terminal in this directory. Quick Start: You already have a default page in the new app, so fire up your server with python3 manage.py runserver and go to You should see a congratulations page. If you don t, go back to the installation section and walk through the steps again. Your console might have valuable error messages to help troubleshoot things. For the Impatient If you are an experienced web developer and just want to get going, check out the example files in your new app: homepage/template/base.htm homepage/template/index.htm homepage/styles/index.css homepage/scripts/index.js These files contain example code that follows the primary patterns of DMP. 20 Chapter 4. Contents

25 Your New App Let s explore the directory structure of your new app: homepage/ media/ scripts/ index.js styles/ base.css index.css templates/ base_ajax.htm base.htm index.html views/ init.py init.py apps.py models.py tests.py The directories should be fairly self-explanatory. Note they are different than a traditional Django app structure. In short, put images and other support files in media/, Javascript in scripts/, CSS in styles/, html files in templates/, and Django views in views/. Note that a common pattern among Django developers is converting several files to directories: models. py to models/ and tests.py to tests/, but that s a discussion outside of DMP. The following setting is automatically done when you created your app, but if you created your app structure manually, DMP-enabled apps must have the following in the appname/ init.py file: DJANGO_MAKO_PLUS = True Let s start with the two primary html template files: base.htm and index.html. index.html is pretty simple: <%inherit file="base.htm" /> <%block name="content"> <div class="content"> <h3>congratulations -- you've successfully created a new django-mako-plus app!</ h3> <h4>next Up: Go through the django-mako-plus tutorial and add Javascript, CSS, and urlparams to this page.</h4> <h4 class="utc-time">current time in UTC: ${ utc_time }</h4> </div> </%block> If you are familiar with Django templates, you ll recognize the template inheritance in the <%inherit/> tag. However, this is Mako code, not Django code, so the syntax is a little different. The file defines a single block, called content, that is plugged into the block by the same name in the code below. The real HTML is kept in the base.htm file. It looks like this: ## this is the skeleton of all pages on in this app - it defines the basic html tags <!DOCTYPE html> <html> 4.4. Tutorial 21

26 <meta charset="utf-8"> <head> <title>homepage</title> ## add any site-wide scripts or CSS here; for example, jquery: <script src=" </script> </head> <body> </body> </html> ## render the static file links with the same name as this template <script src="/django_mako_plus/dmp-common.min.js"></script> ${ django_mako_plus.links(self) } <header> <h1>welcome to the homepage app!<h1> </header> <main> <%block name="content"> Site content goes here in sub-templates. </%block> </main> Pay special attention to the <%block name="content"> section, which is overridden in index.html. The page given to the browser will look exactly like base.htm, but the content block will come from index.html rather than the one defined in the supertemplate. The purpose of the inheritance from base.htm is to get a consistent look, menu, etc. across all pages of your site. When you create additional pages, simply override the content block, similar to the way index.html does it. Don t erase anything in the base.htm file. In particular, django_mako_plus.links() and the dmp-common.min.js script are important. As much as you probably want to clean up the mess, try your best to leave these alone. Undefined object has no attribute get_static : If you get this error, you might need to update a setting in settings.py. Ensure that DMP is imported in the DEFAULT_TEMPLATE_IMPORTS list: 'DEFAULT_TEMPLATE_IMPORTS': [ 'import django_mako_plus', ] Then clear out the compiled templates caches: python manage.py dmp_cleanup DMP_CONTEXT is not defined If you get this error, the /django_mako_plus/dmp-common.min.js script is not being loaded. Check the following: Is the <script> tag for this file in your base.htm? If there, did it get moved below the links() call? This 22 Chapter 4. Contents

27 script must be loaded on every page of your site (i.e. in the base template), and it must be loaded before DMP calls are made. Is the url pattern for this file working? Check your urls.py file for include('django_mako_plus. urls'). The DMP urls.py file contains a direct pattern for this file that allows Django to find it. Goodbye, urls.py In the installation procedures above, you set your urls.py file to look something like the following: from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ # the built-in Django administrator url(r'^admin/', admin.site.urls), # urls for any third-party apps go here ] # adds all DMP-enabled apps url('', include('django_mako_plus.urls')), Rather than listing every. single. page. on. your. site. in the urls.py file, the router figures out the destination via a convention. The first url part is taken as the app to go to, and the second url part is taken as the view to call. See the advanced topics if you want to customize this behavior. For example, the url /homepage/index/ routes as follows: The first url part homepage specifies the app that will be used. The second url part index specifies the view or html page within the app. In our example: The router first looks for homepage/views/index.py. In this case, it fails because we haven t created it yet. It then looks for homepage/templates/index.html. It finds the file, so it renders the html through the Mako templating engine and returns it to the browser. The above illustrates the easiest way to show pages: simply place.html files in your templates/ directory. This is useful for pages that don t have any work to do. Examples might be the About Us and Terms of Service pages. There s usually no functionality or permissions issues with these pages, so no view function is required. You might be wondering about default URLs, such as When the url doesn t contain the app and the page, DMP uses the default app and page specified in your settings. Read more on this at Default App and Page T2:.py View Files Contents T2:.py View Files The Render Functions But That s Not Django! 4.4. Tutorial 23

28 Further Reading Let s add some work to the process by adding the current server time to the index page. Empty out homepage/ views/index.py and copy this code into it: from django.conf import settings from django_mako_plus import view_function from datetime import def process_request(request): context = { 'now': datetime.now(), } return request.dmp.render('index.html', context) Reload your server and browser page, and you should see the exact same page. It might look the same, but something very important happened in the routing. Rather than going straight to the index.html page, processing went to your new index.py file. At the end of the process_request function above, we manually render the index.html file. In other words, we re now doing extra work before the rendering. This is the place to do database connections, modify objects, prepare and handle forms, etc. It keeps complex code out of your html pages. Let me pause for a minute and talk about log messages. If you enabled the logger in the installation, you should see the following in your console: DEBUG::DMP variables set by urls.py: ['dmp_app', 'dmp_page', 'urlparams']; variables set by defaults: ['dmp_function']. INFO::DMP processing: app=homepage, page=index, module=homepage.views.index, func=process_request, urlparams=[''] INFO::DMP calling view function homepage.views.index.process_request DEBUG::DMP rendering template /Users/conan/Documents/data/teaching/2017/IS / fomoproject/homepage/templates/index.html These debug statements are incredibly helpful in figuring out why pages aren t routing right. If your page didn t load right, you ll probably see why in these statements. In my log above, the first line lists what named parameters were matched in urls.py. The second line shows the how these named (or defaulted) parameters translated into the app, page, module, and function. The third line shows the controller found the index.py view, and it called the process_request function successfully. This is important the process_request function is the default view function. This web-accessible function must be decorated This decoration is done for security. If the framework were to allow browsers specify any old function, end users could invoke any function of any module on your system! By requiring the decorator, the framework limits end users to one specifically-named function. You can have multiple decorators on your function, such as a permissions check and view_function. The order isn t important unless the other decorators don t wrap the function correctly. is listed first, you won t have def process_request(request): Chapter 4. Contents

29 Later in the tutorial, we ll describe another way to call other functions within your view Even though process_request is the default function, you can actually have multiple web-accessible functions within a single.py file. As stated earlier, we explicitly call the Mako renderer at the end of the process_request function. The context (the third parameter of the call) is a dictionary containing variables to be passed to the template. Let s use the now variable in our index.html template: <%inherit file="base.htm" /> <%block name="content"> <div class="content"> <h3>congratulations -- you've successfully created a new django-mako-plus app!</ h3> <h4>next Up: Go through the django-mako-plus tutorial and add Javascript, CSS, and urlparams to this page.</h4> <p class="server-time">the current server time is ${ now }.</p> <p class="browser-time">the current browser time is...</p> </div> </%block> The ${ varname } code is Mako syntax and is described more fully on the Mako web site. Right now, it s most important that you see how to send data from the view to the template. If you already know Django templates, it should be familiar. Reload your web page and ensure the new view is working correctly. You should see the server time printed on the screen. Each time you reload the page, the time changes. The Render Functions This section explains the two render functions included with DMP. If you just want to get things working, skip over this section. You can always come back later for an explanation of how things are put together. In the example above, we used the dmp_render function to render our template. It s the DMP equivalent of Django s render shortcut function. The primary difference between the two functions (other than, obviously, the names) is DMP s function is coupled to the current app. In contrast, Django searches for templates in a flat list of directories while your apps might have templates in them, Django just searches through them in order. DMP s structure is logically app-based: each of your apps contains a templates directory, and DMP always searches the current app directly. With DMP, there are no worries about template name clashes or finding issues. At the beginning of each request, DMP s middleware determines the current app (i.e. the first item in the url) and adds two render functions to the request object. These are available throughout your request, with no imports needed. As long as you are rendering a template in the request s current app, DMP knows where to find the template file. DMP provides a second function, dmp_render_to_string. This is nearly the same as dmp_render, but dmp_render_to_string returns a string rather than an HttpResponse object. You really don t need to worry about any of this. Templates are rendered in the current app 99% of the time, so just use this code unless you are in a special use case: from django.conf import settings from django_mako_plus import view_function from datetime import 4.4. Tutorial 25

30 def process_request(request): context = { 'now': datetime.now(), } return request.dmp.render('index.html', context) But That s Not Django! In the above code, you may have noticed that we didn t use the normal Django shortcuts like render and render_to_response. DMP provides the shortcuts like dmp_render because its renderers are tied to apps (which is different than Django). But that doesn t mean you can t use the standard Django shortcuts, TemplateResponse, and SimpleTemplateResponse with DMP. There s a full page devoted to the topic, so take a side trip to the topic on Django Template Functions if you want to stick to the normal Django API. Further Reading The advanced topic on templates expands with the following topics: Templates in other apps Templates in other directories, even outside the project Controlling content types and HTTP codes Convenience functions T3: URL Parameters Contents T3: URL Parameters What About Django Path Converters? At a Glance A New View Function Signature For More Information Django is all about pretty URLs. In keeping with that philosophy, we present URL parameters. You ve already used the beginning parts of the URL: the first specifies the app, the second specifies the view/template. URL parameters are the third part, fourth part, and so on. In traditional web links, we specify parameters using key=value pairs, as in /homepage/index? product=144&model=a58ux. That s ugly, and it s certainly not the Django way. What About Django Path Converters? One of the big changes in Django 2.0 (late 2017) is simplified URLs, including automatic parameter conversion. You might be wondering how the two relate to one another. 26 Chapter 4. Contents

31 DMP first included automatic parameter conversion in early 2017, and it wasn t influenced by Django s design; the two developed separately. DMP s parameter conversion is different in the following ways: DMP discovers parameters and type hints from your view function signatures; Django uses your patterns in urls.py. Type hints and parameter defaults in DMP are specified the standard Python way. Django uses a custom URL syntax. DMP has more built-in converters: DateTime, Decimal, all Django models, etc. Converters in DMP match using isinstance; converters in Django match by regex match. The conversion method in DMP matches well with its goal of convention-over-configuration. Django s method matches well with its enumerate all urls design. You can use both in the same project; DMP apps do it the DMP way, other apps do it the Django way. At a Glance Compare the old vs. the new: This: /homepage/index? product=144&model=a58ux Longer More difficult to text or Less search engine friendly A face only a programmer could love... Becomes This: /homepage/index/144/a58ux/ Shorter Easier to text or More search engine friendly URL parameters don t take the place of form parameters. You ll still use GET and POST parameters to submit forms. You ll still use name/value pairs when it makes sense, such as on a search page. URL parameters are best used for object ids and other simple items that pages need to display, such as the product id in the previous example. DMP sends extra parameters (411 and A58UX above) to your view function. You only need to add variables for these parameters to your view function signature. In addition, DMP automatically converts values into ints, booleans, and even your Models. A New View Function Signature Let s modify homepage/views/index.py to support adjusting the current date by a certain amount of time. We ll specify the hours, minutes, and direction in the URL: from django.conf import settings from django_mako_plus import view_function from datetime import datetime, def process_request(request, hrs, mins, forward='+'): delta = timedelta(hours=int(hrs), minutes=int(mins)) if forward == '+': now = datetime.now() + delta else: now = datetime.now() - delta context = { 'now': now, 4.4. Tutorial 27

32 } return request.dmp.render('index.html', context) We ll use the homepage/templates/index.html file we created in previous tutorial parts: <%inherit file="base.htm" /> <%block name="content"> <div class="content"> <p class="server-time">the current server time is ${ now }.</p> </div> </%block> Take your browser to It shows a time 6:30 in the future by evaluating the values in the URL. Try different values to adjust the hours, minutes, and direction. Since forward has a default value, it can be omitted: This first example shows how DMP sends URL parts into view functions. It separates the URL parts by the slash /, and positionally matches them to functions. In this simplest of view function signatures, the parameters are strings. If you are using multiple decorators on your endpoints, you can save a lot of trouble by checking that your decorators are wrapping correctly. Adding Type Hints But what if you need integers, booleans, or even Model instances, such as a User object, Purchase object, or Question object? By adding type hints (yes, they re in the standard Python langauge), we can have them converted to the right type automatically. Add the following type hints to your process_request function, and remove the typecasting calls: from django.conf import settings from django_mako_plus import view_function from datetime import datetime, def process_request(request, hrs:int, mins:int, forward:bool=true): delta = timedelta(hours=hrs, minutes=mins) if forward: now = datetime.now() + delta else: now = datetime.now() - delta context = { 'now': now, } return request.dmp.render('index.html', context) DMP casts the parameters by inspecting the method signature of process_request which specifies the parameter name, a color, and the type. If a conversion error occurs, the default converter raises Http404. All of this is configurable and extensible (read on). Automatic Model Conversion DMP converts all of the Model classes in your project. Suppose we have an model called storefront.purchase. If we list this type as the type hint, DMP will pull the object from the database automatically: 28 Chapter 4. Contents

33 from django_mako_plus import view_function from storefront.models import def process_request(request, purchase:purchase): # the `purchase` variable has already been pulled from the database In the above code, one of two outcomes will occur: If a Purchase record with primary key 1501 exists in the database, it is sent into the function. If it doesn t exist, DMP raises Http404. For More Information The advanced topic on conversion expands the topics above. Come back later if you want to continue the discussion on parameter conversion T4: zip(html, JS, CSS) Contents T4: zip(html, JS, CSS) A Bit of Style Javascript Javascript in Context Bundlers like Webpack, Browserify, etc. Behind the CSS and JS Curtain Modern web pages are made up of three primary parts: HTML, CSS, and Javascript (media might be a fourth, but we ll go with three for now). Since all of your pages need these three components, this framework combines them intelligently for you. All you have to do is name the.html, the css., and the.js files correctly, and DMP will insert the <link> and <script> tags automatically for you. Convention over configuration. Just like a slice of home-baked apple pie. A Bit of Style To style our index.html file, open homepage/styles/index.css and copy the following into it:.server-time { font-size: 2em; color: red; } When you refresh your page, the server time should be styled with large, red text. If you view the html source in your browser, you ll see a new <link...> near the top of your file. It s as easy as naming the files the same and placing the.css file in the styles/ directory Tutorial 29

34 The framework knows how to follow template inheritance. For example, since index.html extends from base. htm, we can actually put our CSS in either: index.css or base.css. Place your CSS styles in the appropriate file, depending on where the HTML elements are located. For example, let s style our header a little. Since the <header> element is in base.htm, open homepage/styles/base.css and check for the following: html, body { margin: 0; padding: 0; } header { background-color: #147871; padding: 15px 20px; border-top: 4px solid #606060; border-bottom: 4px solid #606060; } header h1 { color: #FFFFFF; margin: 0; padding: 0; } main { margin: 0; padding: 15px; } Since base.htm will be the parent page of nearly every HTML page on your site, these common styles will apply to all pages. If you view source in the browser, you ll see the CSS files were included as follows: <link rel="stylesheet" type="text/css" href="/static/homepage/styles/base.css? " /> <link rel="stylesheet" type="text/css" href="/static/homepage/styles/index.css? " /> Note that base.css is included first because it s at the top of the hierarchy. Styles from index.css override any conflicting styles from base.css, which makes sense because index.html is the final template in the inheritance chain. You might be wondering about the big number after the html source <link>. That s the file modification time, in minutes since This is included because browsers don t automatically download new CSS files (I m looking at you here Chrome!). They use their cached versions until a specified date, often far in the future (this duration is set by your web server). By adding a number to the end of the file, browsers think the CSS files are new because the filename changes whenever you change the file. Trixy browserses... Javascript Javascript files work the same way as CSS files, so if you skipped the CSS sections above, you might want to go read through them. Javascript files are placed in the scripts/ directory and, of course, end with *.js extension. Let s add a client-side, Javascript-based timer. Create the file homepage/scripts/index.js and place the following JQuery code into it: $(function() { // update the time every 1 seconds 30 Chapter 4. Contents

35 }); window.setinterval(function() { $('.browser-time').text('the current browser time is ' + new Date() + '.'); }, 1000); Refresh your browser page, and you should see the browser time updating each second. Congratulations, you ve now got a modern, HTML5 web page. Javascript in Context What if we need to get a value from our Python view code, such as the server time, into the index.js file? DMP handles this too. Lets compare the server time with the browser time allows us to calculate the time zone difference between the two. To send a variable to the JS environment, tag it with jscontext(). Change your index.py file to the following: from django.conf import settings from django_mako_plus import view_function, jscontext from datetime import def process_request(request): context = { jscontext('now'): datetime.now(), } return request.dmp.render('index.html', context) Reload your browser, and then right-click and Inspect to see your DOM. The <script> tag now looks like this: <script type="text/javascript" src="/static/homepage/scripts/index.js? " data-context="u5a befacbc327df "></script> When you tag a context key with jscontext('now'), DMP adds it to a context object and connects it via data-context. Note that variables sent via jscontext must be serializable by Django s django.core. serializers.json.djangojsonencoder (although you can set a custom encoder if needed). The default encoder includes all the typical types, plus datetime, date, time, timedelta, Decimal, and UUID. Let s use the variable in index.js: $(function(context) { return function() { console.log(context) var servertime = new Date(context.now) // server time (from DMP_CONTEXT) var browsertime = new Date() // browser time var hours = Math.round(Math.abs(serverTime - browsertime) / 36e5) $('.browser-time').text('the current browser is ' + hours + ' hours off of the server time zone.') } }(DMP_CONTEXT.get())) Reload your browser, and you should see the calculation of hours. The context is sent to the script via a data attribute on the <script> element. The closure surrounding everything keeps the variable local to this script. Read more about this in the topic on CSS and JS. Also, see providers for the es6 arrow-style syntax for this closure Tutorial 31

36 Bundlers like Webpack, Browserify, etc. If you are using JS bundles, DMP files can go right in the bundles. See bundling in Rendering CSS and JS for more information. Behind the CSS and JS Curtain After reading about automatic CSS and JS inclusion, you might want to know how it works. It s all done in the templates (base.htm now, and base_ajax.htm in a later section below) you are inheriting from. Open base.htm and look at the following code: ## render the static file links for this template <script src="/django_mako_plus/dmp-common.min.js"></script> ${ django_mako_plus.links(self) } The calls to links() include the <link> and <script> tags for the template name and all of its supertemplates. These links are placed at the end of your <head> section. (Just a few years ago, common practice was to place script tags at the end of the body, but modern browsers with asyncronous and deferred scripts have put them back in the body.) This all works because the index.html template extends from the base.htm template. If you fail to inherit from base.htm or base_ajax.htm, DMP won t be able to include the support files. Read more about providers in Rendering CSS and JS T5: Ajax Contents T5: Ajax A Simple Example Really, a Whole New File for Ajax? What would the modern web be without Ajax? Truthfully... a lot simpler. :) In fact, if we reinvented the web with today s requirements, we d probably end up at a very different place than our current web. Even the name ajax implies the use of xml which we don t use much in ajax anymore. Most ajax calls return json or html these days! But regardless of web history, ajax is required on most pages today. I ll assume you understand the basics of ajax and focus specifically on the ways this framework supports it. A Simple Example Suppose we want to reload the server time every few seconds, but we don t want to reload the entire page. Let s start with the client side of things. Let s place a refresh button in homepage/templates/index.html: <%inherit file="base.htm" /> <%block name="content"> <div class="content"> <h3>congratulations -- you've successfully created a new django-mako-plus app!</ h3> <h4>next Up: Go through the django-mako-plus tutorial and add Javascript, CSS, and urlparams to this page.</h4> 32 Chapter 4. Contents

Building a Django Twilio Programmable Chat Application

Building a Django Twilio Programmable Chat Application Building a Django Twilio Programmable Chat Application twilio.com/blog/08/0/python-django-twilio-programmable-chat-application.html March 7, 08 As a developer, I ve always wanted to include chat capabilities

More information

Django urls Django Girls Tutorial

Django urls Django Girls Tutorial Django urls Django Girls Tutorial about:reader?url=https://tutorial.djangogirls.org/en/django_urls/ 1 di 6 13/11/2017, 20:01 tutorial.djangogirls.org Django urls Django Girls Tutorial DjangoGirls 6-8 minuti

More information

django-baton Documentation

django-baton Documentation django-baton Documentation Release 1.0.7 abidibo Nov 13, 2017 Contents 1 Features 3 2 Getting started 5 2.1 Installation................................................ 5 2.2 Configuration...............................................

More information

django-scaffold Documentation

django-scaffold Documentation django-scaffold Documentation Release 1.1.1 James Stevenson May 27, 2015 Contents 1 Installation 3 2 Creating an app to extend scaffold 5 2.1 1. Create a new application........................................

More information

wagtailmenus Documentation

wagtailmenus Documentation wagtailmenus Documentation Release 2.12 Andy Babic Nov 17, 2018 Contents 1 Full index 3 1.1 Overview and key concepts....................................... 3 1.1.1 Better control over top-level menu

More information

Quick.JS Documentation

Quick.JS Documentation Quick.JS Documentation Release v0.6.1-beta Michael Krause Jul 22, 2017 Contents 1 Installing and Setting Up 1 1.1 Installation................................................ 1 1.2 Setup...................................................

More information

django-baton Documentation

django-baton Documentation django-baton Documentation Release 1.3.1 abidibo Nov 05, 2018 Contents 1 Features 3 2 Getting started 5 2.1 Installation................................................ 5 2.2 Configuration...............................................

More information

Client Side JavaScript and AJAX

Client Side JavaScript and AJAX Client Side JavaScript and AJAX Client side javascript is JavaScript that runs in the browsers of people using your site. So far all the JavaScript code we've written runs on our node.js server. This is

More information

wagtailmenus Documentation

wagtailmenus Documentation wagtailmenus Documentation Release 2.11 Andy Babic Aug 02, 2018 Contents 1 Full index 3 1.1 Overview and key concepts....................................... 3 1.1.1 Better control over top-level menu

More information

MIT AITI Python Software Development Lab DJ1:

MIT AITI Python Software Development Lab DJ1: MIT AITI Python Software Development Lab DJ1: This lab will help you get Django installed and write your first application. 1 Each person in your group must complete this lab and have it checked off. Make

More information

django-ad-code Documentation

django-ad-code Documentation django-ad-code Documentation Release 1.0.0 Mark Lavin Apr 21, 2018 Contents 1 Installation 3 2 Documentation 5 3 License 7 4 Contributing 9 5 Contents 11 5.1 Getting Started..............................................

More information

Graphene Documentation

Graphene Documentation Graphene Documentation Release 1.0.dev Syrus Akbary Nov 09, 2017 Contents 1 Introduction tutorial - Graphene and Django 3 1.1 Set up the Django project........................................ 3 1.2 Hello

More information

CSCU9B2 Practical 1: Introduction to HTML 5

CSCU9B2 Practical 1: Introduction to HTML 5 CSCU9B2 Practical 1: Introduction to HTML 5 Aim: To learn the basics of creating web pages with HTML5. Please register your practical attendance: Go to the GROUPS\CSCU9B2 folder in your Computer folder

More information

Django File Picker Documentation

Django File Picker Documentation Django File Picker Documentation Release 0.5 Caktus Consulting Group LLC Nov 06, 2017 Contents 1 Dependencies 3 1.1 Required................................................. 3 1.2 Optional.................................................

More information

Quick housekeeping Last Two Homeworks Extra Credit for demoing project prototypes Reminder about Project Deadlines/specifics Class on April 12th Resul

Quick housekeeping Last Two Homeworks Extra Credit for demoing project prototypes Reminder about Project Deadlines/specifics Class on April 12th Resul CIS192 Python Programming Web Frameworks and Web APIs Harry Smith University of Pennsylvania March 29, 2016 Harry Smith (University of Pennsylvania) CIS 192 March 29, 2016 1 / 25 Quick housekeeping Last

More information

django-session-security Documentation

django-session-security Documentation django-session-security Documentation Release 2.5.1 James Pic Oct 27, 2017 Contents 1 Why not just set the session to expire after X minutes? 3 2 How does it work? 5 3 Requirements 7 4 Resources 9 4.1

More information

Django Test Utils Documentation

Django Test Utils Documentation Django Test Utils Documentation Release 0.3 Eric Holscher July 22, 2016 Contents 1 Source Code 3 2 Contents 5 2.1 Django Testmaker............................................ 5 2.2 Django Crawler.............................................

More information

wagtailtrans Documentation

wagtailtrans Documentation wagtailtrans Documentation Release 0.1.0 LUKKIEN Jul 27, 2018 Contents 1 Table of contents 3 1.1 Getting started.............................................. 3 1.2 Migrate your existing Wagtail site....................................

More information

Section 1. How to use Brackets to develop JavaScript applications

Section 1. How to use Brackets to develop JavaScript applications Section 1 How to use Brackets to develop JavaScript applications This document is a free download from Murach books. It is especially designed for people who are using Murach s JavaScript and jquery, because

More information

Unifer Documentation. Release V1.0. Matthew S

Unifer Documentation. Release V1.0. Matthew S Unifer Documentation Release V1.0 Matthew S July 28, 2014 Contents 1 Unifer Tutorial - Notes Web App 3 1.1 Setting up................................................. 3 1.2 Getting the Template...........................................

More information

HTML/CSS Lesson Plans

HTML/CSS Lesson Plans HTML/CSS Lesson Plans Course Outline 8 lessons x 1 hour Class size: 15-25 students Age: 10-12 years Requirements Computer for each student (or pair) and a classroom projector Pencil and paper Internet

More information

django-sticky-uploads Documentation

django-sticky-uploads Documentation django-sticky-uploads Documentation Release 0.2.0 Caktus Consulting Group October 26, 2014 Contents 1 Requirements/Installing 3 2 Browser Support 5 3 Documentation 7 4 Running the Tests 9 5 License 11

More information

nacelle Documentation

nacelle Documentation nacelle Documentation Release 0.4.1 Patrick Carey August 16, 2014 Contents 1 Standing on the shoulders of giants 3 2 Contents 5 2.1 Getting Started.............................................. 5 2.2

More information

Djam Documentation. Release Participatory Culture Foundation

Djam Documentation. Release Participatory Culture Foundation Djam Documentation Release 0.1.0 Participatory Culture Foundation December 24, 2013 Contents 1 Links 3 2 Getting Started 5 2.1 Quick Start................................................ 5 2.2 Extending

More information

web.py Tutorial Tom Kelliher, CS 317 This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment.

web.py Tutorial Tom Kelliher, CS 317 This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment. web.py Tutorial Tom Kelliher, CS 317 1 Acknowledgment This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment. 2 Starting So you know Python and want to make

More information

CSS BASICS. selector { property: value; }

CSS BASICS. selector { property: value; } GETTING STARTED 1. Download the Juice-o-Rama 11-01 zip file from our course dropbox. 2. Move the file to the desktop. You have learned two ways to do this. 3. Unzip the file by double clicking it. You

More information

webkitpony Documentation

webkitpony Documentation webkitpony Documentation Release 0.1 Toni Michel May 24, 2014 Contents 1 Motivation 3 2 Goal 5 3 Understanding webkitpony 7 3.1 Understanding webkitpony........................................ 7 3.2 The

More information

AP CS P. Unit 2. Introduction to HTML and CSS

AP CS P. Unit 2. Introduction to HTML and CSS AP CS P. Unit 2. Introduction to HTML and CSS HTML (Hyper-Text Markup Language) uses a special set of instructions to define the structure and layout of a web document and specify how the document should

More information

The Django Web Framework Part II. Hamid Zarrabi-Zadeh Web Programming Fall 2013

The Django Web Framework Part II. Hamid Zarrabi-Zadeh Web Programming Fall 2013 The Django Web Framework Part II Hamid Zarrabi-Zadeh Web Programming Fall 2013 2 Outline Overview Making the Front Page Creating the Template Creating View Functions Configuring URL Patterns Finishing

More information

Using GitHub to Share with SparkFun a

Using GitHub to Share with SparkFun a Using GitHub to Share with SparkFun a learn.sparkfun.com tutorial Available online at: http://sfe.io/t52 Contents Introduction Gitting Started Forking a Repository Committing, Pushing and Pulling Syncing

More information

Django. Jinja2. Aymeric Augustin DjangoCong 2016

Django. Jinja2. Aymeric Augustin DjangoCong 2016 Django Jinja2 Aymeric Augustin DjangoCong 2016 Jardin des Plantes, Avranches, 9 avril 2016 I m Aymeric Amalfi Core Developer since 2011 Chief Technical Officer since 2015 Time zones Python 3 Transactions

More information

Django-CSP Documentation

Django-CSP Documentation Django-CSP Documentation Release 3.0 James Socol, Mozilla September 06, 2016 Contents 1 Installing django-csp 3 2 Configuring django-csp 5 2.1 Policy Settings..............................................

More information

HTML5: Adding Style. Styling Differences. HTML5: Adding Style Nancy Gill

HTML5: Adding Style. Styling Differences. HTML5: Adding Style Nancy Gill HTML5: Adding Style In part 2 of a look at HTML5, Nancy will show you how to add CSS to the previously unstyled document from part 1 and why there are some differences you need to watch out for. In this

More information

2. Write style rules for how you d like certain elements to look.

2. Write style rules for how you d like certain elements to look. CSS for presentation Cascading Style Sheet Orientation CSS Cascading Style Sheet is a language that allows the user to change the appearance or presentation of elements on the page: the size, style, and

More information

django-dajaxice Documentation

django-dajaxice Documentation django-dajaxice Documentation Release 0.7 Jorge Bastida Nov 17, 2017 Contents 1 Documentation 3 1.1 Installation................................................ 3 1.2 Quickstart................................................

More information

django-ratelimit-backend Documentation

django-ratelimit-backend Documentation django-ratelimit-backend Documentation Release 1.2 Bruno Renié Sep 13, 2017 Contents 1 Usage 3 1.1 Installation................................................ 3 1.2 Quickstart................................................

More information

EmberJS A Fitting Face for a D8 Backend. Taylor Solomon

EmberJS A Fitting Face for a D8 Backend. Taylor Solomon EmberJS A Fitting Face for a D8 Backend Taylor Solomon taylor.solomon @jtsolomon http://interactivestrategies.com 2 Years Ago 2 Years Ago URL Ember Data assumes a few things. - Your API format is JSON

More information

Using Dreamweaver CC. Logo. 4 Creating a Template. Page Heading. Page content in this area. About Us Gallery Ordering Contact Us Links

Using Dreamweaver CC. Logo. 4 Creating a Template. Page Heading. Page content in this area. About Us Gallery Ordering Contact Us Links Using Dreamweaver CC 4 Creating a Template Now that the main page of our website is complete, we need to create the rest of the pages. Each of them will have a layout that follows the plan shown below.

More information

Release Joris Beckers

Release Joris Beckers django a uth a dfsdocumentation Release 0.2.0 Joris Beckers Sep 14, 2017 Contents 1 Features 3 2 Contents 5 2.1 Installation................................................ 5 2.1.1 Requirements..........................................

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Laravel

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Laravel About the Tutorial Laravel is a powerful MVC PHP framework, designed for developers who need a simple and elegant toolkit to create full-featured web applications. Laravel was created by Taylor Otwell.

More information

yawrap Documentation Release Michal Kaczmarczyk

yawrap Documentation Release Michal Kaczmarczyk yawrap Documentation Release 0.4.0 Michal Kaczmarczyk Jul 12, 2018 Contents 1 Features 3 2 Usage Examples 5 3 Contents 11 4 Indices and tables 19 i ii Yawrap is a powerful, lightweight, pythonic pseudo-static

More information

Web Development for Dinosaurs An Introduction to Modern Web Development

Web Development for Dinosaurs An Introduction to Modern Web Development Web Development for Dinosaurs An Introduction to Modern Web Development 1 / 53 Who Am I? John Cleaver Development Team Lead at Factivity, Inc. An Introduction to Modern Web Development - PUG Challenge

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Web Servers and Web APIs Raymond Yin University of Pennsylvania November 12, 2015 Raymond Yin (University of Pennsylvania) CIS 192 November 12, 2015 1 / 23 Outline 1 Web Servers

More information

django-xross Documentation

django-xross Documentation django-xross Documentation Release 0.6.0 Igor idle sign Starikov Jan 14, 2018 Contents 1 Description 3 2 Requirements 5 3 Table of Contents 7 3.1 Quickstart................................................

More information

Django EL(Endless) Pagination Documentation

Django EL(Endless) Pagination Documentation Django EL(Endless) Pagination Documentation Release 2.1.0 Oleksandr Shtalinberg and Francesco Banconi December 07, 2015 Contents 1 Changelog 3 1.1 Version 2.1.0...............................................

More information

Django starting guide

Django starting guide Django starting guide (and much more ) Alessandro Bucciarelli Outline Lesson 1 Intro to versioning systems (Git) Intro to Python and basic data structures Django Lesson 2 Interaction between Django and

More information

These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

More information

Week 8 Google Maps. This week you ll learn how to embed a Google Map into a web page and add custom markers with custom labels.

Week 8 Google Maps. This week you ll learn how to embed a Google Map into a web page and add custom markers with custom labels. Introduction Hopefully by now you ll have seen the possibilities that jquery provides for rich content on web sites in the form of interaction and media playback. This week we ll be extending this into

More information

CISC-124. Casting. // this would fail because we can t assign a double value to an int // variable

CISC-124. Casting. // this would fail because we can t assign a double value to an int // variable CISC-124 20180122 Today we looked at casting, conditionals and loops. Casting Casting is a simple method for converting one type of number to another, when the original type cannot be simply assigned to

More information

Using Dreamweaver CS6

Using Dreamweaver CS6 Using Dreamweaver CS6 4 Creating a Template Now that the main page of our website is complete, we need to create the rest of the pages. Each of them will have a layout that follows the plan shown below.

More information

Django PAM Documentation

Django PAM Documentation Django PAM Documentation Release 1.4.1 Carl J. Nobile Aug 01, 2018 Contents 1 Contents 3 1.1 Installation................................................ 3 1.2 Configuration...............................................

More information

One of the fundamental kinds of websites that SharePoint 2010 allows

One of the fundamental kinds of websites that SharePoint 2010 allows Chapter 1 Getting to Know Your Team Site In This Chapter Requesting a new team site and opening it in the browser Participating in a team site Changing your team site s home page One of the fundamental

More information

ASP.NET MVC Training

ASP.NET MVC Training TRELLISSOFT ASP.NET MVC Training About This Course: Audience(s): Developers Technology: Visual Studio Duration: 6 days (48 Hours) Language(s): English Overview In this course, students will learn to develop

More information

In fact, as your program grows, you might imagine it organized by class and superclass, creating a kind of giant tree structure. At the base is the

In fact, as your program grows, you might imagine it organized by class and superclass, creating a kind of giant tree structure. At the base is the 6 Method Lookup and Constant Lookup As we saw in Chapter 5, classes play an important role in Ruby, holding method definitions and constant values, among other things. We also learned how Ruby implements

More information

Django File Picker Documentation

Django File Picker Documentation Django File Picker Documentation Release 0.5 Caktus Consulting Group LLC Oct 31, 2017 Contents 1 Dependencies 3 1.1 Required................................................. 3 1.2 Optional.................................................

More information

MapEntity Documentation

MapEntity Documentation MapEntity Documentation Release 0.1.0 Makina Corpus Jun 11, 2018 Contents 1 Installation 3 1.1 Quickstart................................................ 3 1.2 Manual installation With a PostGIS database..............................

More information

Django Standalone Apps

Django Standalone Apps Django Standalone Apps A developer s fieldguide to developing reusable Django applications Ben Lopatin 2015-2016 Ben Lopatin Contents Just a sample................................... Introduction...................................

More information

Episode 298. Getting Started With Spree

Episode 298. Getting Started With Spree Episode 298 Getting Started With Spree Spree 1 is a fully-featured e-commerce solution that can be easily integrated into a Rails application. If you need to turn a Rails app into a store that sells products

More information

Lab 1 - Introduction to Angular

Lab 1 - Introduction to Angular Lab 1 - Introduction to Angular In this lab we will build a Hello World style Angular component. The key focus is to learn how to install all the required code and use them from the browser. We wont get

More information

ThingLink User Guide. Andy Chen Eric Ouyang Giovanni Tenorio Ashton Yon

ThingLink User Guide. Andy Chen Eric Ouyang Giovanni Tenorio Ashton Yon ThingLink User Guide Yon Corp Andy Chen Eric Ouyang Giovanni Tenorio Ashton Yon Index Preface.. 2 Overview... 3 Installation. 4 Functionality. 5 Troubleshooting... 6 FAQ... 7 Contact Information. 8 Appendix...

More information

Developing ASP.NET MVC 4 Web Applications

Developing ASP.NET MVC 4 Web Applications Developing ASP.NET MVC 4 Web Applications Duration: 5 Days Course Code: 20486B About this course In this course, students will learn to develop advanced ASP.NET MVC applications using.net Framework 4.5

More information

Django_template3d Documentation

Django_template3d Documentation Django_template3d Documentation Release 0.0.1 Robert Steckroth August 27, 2016 Contents 1 Getting Started 3 1.1 Quick Install............................................... 3 2 Learning Template3d 5 2.1

More information

Using Development Tools to Examine Webpages

Using Development Tools to Examine Webpages Chapter 9 Using Development Tools to Examine Webpages Skills you will learn: For this tutorial, we will use the developer tools in Firefox. However, these are quite similar to the developer tools found

More information

We are assuming you have node installed!

We are assuming you have node installed! Node.js Hosting We are assuming you have node installed! This lesson assumes you've installed and are a bit familiar with JavaScript and node.js. If you do not have node, you can download and install it

More information

XP: Backup Your Important Files for Safety

XP: Backup Your Important Files for Safety XP: Backup Your Important Files for Safety X 380 / 1 Protect Your Personal Files Against Accidental Loss with XP s Backup Wizard Your computer contains a great many important files, but when it comes to

More information

SASS Variables and Mixins Written by Margaret Rodgers. Variables. Contents. From Web Team. 1 Variables

SASS Variables and Mixins Written by Margaret Rodgers. Variables. Contents. From Web Team. 1 Variables SASS Variables and Mixins Written by Margaret Rodgers From Web Team Contents 1 Variables o 1.1 Nested Variables 2 Mixins 3 Inheritance Variables A variable in SASS works exactly the same as a variable

More information

Rapid Development with Django and App Engine. Guido van Rossum May 28, 2008

Rapid Development with Django and App Engine. Guido van Rossum May 28, 2008 Rapid Development with Django and App Engine Guido van Rossum May 28, 2008 Talk Overview This is not a plug for Python, Django or Google App Engine Except implicitly :) Best practices for using Django

More information

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

More information

CID Documentation. Release Francis Reyes

CID Documentation. Release Francis Reyes CID Documentation Release 0.2.0 Francis Reyes Sep 30, 2017 Contents 1 Django Correlation IDs 1 1.1 Features.................................................. 1 Python Module Index 9 i ii CHAPTER 1 Django

More information

wagtail-robots Documentation

wagtail-robots Documentation wagtail-robots Documentation Release dev Adrian Turjak Feb 28, 2018 Contents 1 Wagtail Robots In Action 3 2 Installation 9 3 Initialization 11 4 Rules 13 5 URLs 15 6 Caching 17 7 Sitemaps 19 8 Host directive

More information

JavaScript Fundamentals_

JavaScript Fundamentals_ JavaScript Fundamentals_ HackerYou Course Syllabus CLASS 1 Intro to JavaScript Welcome to JavaScript Fundamentals! Today we ll go over what programming languages are, JavaScript syntax, variables, and

More information

Before you begin, make sure you have the images for these exercises saved in the location where you intend to create the Nuklear Family Website.

Before you begin, make sure you have the images for these exercises saved in the location where you intend to create the Nuklear Family Website. 9 Now it s time to challenge the serious web developers among you. In this section we will create a website that will bring together skills learned in all of the previous exercises. In many sections, rather

More information

Human-Computer Interaction Design

Human-Computer Interaction Design Human-Computer Interaction Design COGS120/CSE170 - Intro. HCI Instructor: Philip Guo Lab 6 - Connecting frontend and backend without page reloads (2016-11-03) by Michael Bernstein, Scott Klemmer, and Philip

More information

LECTURE 14. Web Frameworks

LECTURE 14. Web Frameworks LECTURE 14 Web Frameworks WEB DEVELOPMENT CONTINUED Web frameworks are collections of packages or modules which allow developers to write web applications with minimal attention paid to low-level details

More information

Table Basics. The structure of an table

Table Basics. The structure of an table TABLE -FRAMESET Table Basics A table is a grid of rows and columns that intersect to form cells. Two different types of cells exist: Table cell that contains data, is created with the A cell that

More information

Techniques for Optimizing Reusable Content in LibGuides

Techniques for Optimizing Reusable Content in LibGuides University of Louisville From the SelectedWorks of Terri Holtze April 21, 2017 Techniques for Optimizing Reusable Content in LibGuides Terri Holtze, University of Louisville Available at: https://works.bepress.com/terri-holtze/4/

More information

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read)

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read) 1 For the remainder of the class today, I want to introduce you to a topic we will spend one or two more classes discussing and that is source code control or version control. What is version control?

More information

Without further ado, let s go over and have a look at what I ve come up with.

Without further ado, let s go over and have a look at what I ve come up with. JIRA Integration Transcript VLL Hi, my name is Jonathan Wilson and I m the service management practitioner with NHS Digital based in the United Kingdom. NHS Digital is the provider of services to the National

More information

We re working full time this summer alongside 3 UCOSP (project course) students (2 from Waterloo: Mark Rada & Su Zhang, 1 from UofT: Angelo Maralit)

We re working full time this summer alongside 3 UCOSP (project course) students (2 from Waterloo: Mark Rada & Su Zhang, 1 from UofT: Angelo Maralit) We re working full time this summer alongside 3 UCOSP (project course) students (2 from Waterloo: Mark Rada & Su Zhang, 1 from UofT: Angelo Maralit) Our supervisors: Karen: heads project, which has been

More information

AngularJS Fundamentals

AngularJS Fundamentals AngularJS Fundamentals by Jeremy Zerr Blog: http://www.jeremyzerr.com LinkedIn: http://www.linkedin.com/in/jrzerr Twitter: http://www.twitter.com/jrzerr What is AngularJS Open Source Javascript MVC/MVVM

More information

Design Document V2 ThingLink Startup

Design Document V2 ThingLink Startup Design Document V2 ThingLink Startup Yon Corp Andy Chen Ashton Yon Eric Ouyang Giovanni Tenorio Table of Contents 1. Technology Background.. 2 2. Design Goal...3 3. Architectural Choices and Corresponding

More information

Unveiling the Basics of CSS and how it relates to the DataFlex Web Framework

Unveiling the Basics of CSS and how it relates to the DataFlex Web Framework Unveiling the Basics of CSS and how it relates to the DataFlex Web Framework Presented by Roel Fermont 1 Today more than ever, Cascading Style Sheets (CSS) have a dominant place in online business. CSS

More information

Course 20486B: Developing ASP.NET MVC 4 Web Applications

Course 20486B: Developing ASP.NET MVC 4 Web Applications Course 20486B: Developing ASP.NET MVC 4 Web Applications Overview In this course, students will learn to develop advanced ASP.NET MVC applications using.net Framework 4.5 tools and technologies. The focus

More information

django-embed-video Documentation

django-embed-video Documentation django-embed-video Documentation Release 1.1.2-stable Juda Kaleta Nov 10, 2017 Contents 1 Installation & Setup 3 1.1 Installation................................................ 3 1.2 Setup...................................................

More information

ganetimgr Documentation

ganetimgr Documentation ganetimgr Documentation Release 1.4.1 GRNET NOC, GRNET S.A May 23, 2014 Contents 1 What is ganetimgr? 1 2 Compatibility 3 3 Installation 5 3.1 ganetimgr installation..........................................

More information

Ruby on Rails Welcome. Using the exercise files

Ruby on Rails Welcome. Using the exercise files Ruby on Rails Welcome Welcome to Ruby on Rails Essential Training. In this course, we're going to learn the popular open source web development framework. We will walk through each part of the framework,

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Web API Lab. The next two deliverables you shall write yourself.

Web API Lab. The next two deliverables you shall write yourself. Web API Lab In this lab, you shall produce four deliverables in folder 07_webAPIs. The first two deliverables should be pretty much done for you in the sample code. 1. A server side Web API (named listusersapi.jsp)

More information

kaleo Documentation Release 1.5 Eldarion

kaleo Documentation Release 1.5 Eldarion kaleo Documentation Release 1.5 Eldarion October 06, 2014 Contents 1 Development 3 1.1 Contents................................................. 3 i ii Provides a site with user to user invitations, working

More information

Django QR Code Documentation

Django QR Code Documentation Django QR Code Documentation Release 0.3.3 Philippe Docourt Nov 12, 2017 Contents: 1 Django QR Code 1 1.1 Installation................................................ 1 1.2 Usage...................................................

More information

Data Visualization on the Web with D3

Data Visualization on the Web with D3 Data Visualization on the Web with D3 Bowen Yu April 11, 16 Big Data Analysis Interactive Analysis After dataprocessingwith BD techniques, itis necessary to visualize the data so that human analyst can

More information

Django Dynamic Fields Documentation

Django Dynamic Fields Documentation Django Dynamic Fields Documentation Release 0.1.0 James Pic Mar 24, 2017 Contents 1 Toc 1 1.1 Design documentation for django-dynamic-field............................ 1 2 Readme 3 3 Example 5 4 Dual-license

More information

Creating a CSS driven menu system Part 1

Creating a CSS driven menu system Part 1 Creating a CSS driven menu system Part 1 How many times do we see in forum pages the cry; I ve tried using Suckerfish, I ve started with Suckerfish and made some minor changes but can t get it to work.

More information

ORB Education Quality Teaching Resources

ORB Education Quality Teaching Resources JavaScript is one of the programming languages that make things happen in a web page. It is a fantastic way for students to get to grips with some of the basics of programming, whilst opening the door

More information

Webpack. What is Webpack? APPENDIX A. n n n

Webpack. What is Webpack? APPENDIX A. n n n APPENDIX A n n n Webpack Although Webpack is used throughout the book, the primary focus of the book is on React, so Webpack didn t get a comprehensive treatment. In this Appendix, you will have the chance

More information

learn programming the right way

learn programming the right way Coding 101 learn programming the right way 1 INTRODUCTION Before you begin learning how to code, it s first useful to discuss why you would want to learn web development. There are lots of good reasons

More information

Building a Python Flask Website A beginner-friendly guide

Building a Python Flask Website A beginner-friendly guide Building a Python Flask Website A beginner-friendly guide PythonHow.com Copyright 2016 PythonHow.com. All rights reserved. 1 Preface This book contains a quick guide on understanding and using the Python

More information

BF Survey Pro User Guide

BF Survey Pro User Guide BF Survey Pro User Guide January 2011 v1.0 1 of 41 www.tamlyncreative.com.au/software/ Table of Contents Introduction... 5 Support... 5 Documentation... 5 Installation New Install... 5 Installation Upgrade...

More information

django-contact-form Documentation

django-contact-form Documentation django-contact-form Documentation Release 1.4.2 James Bennett Aug 01, 2017 Installation and configuration 1 Installation guide 3 2 Quick start guide 5 3 Contact form classes 9 4 Built-in views 13 5 Frequently

More information

Django: Views, Templates, and Sessions

Django: Views, Templates, and Sessions Django: Views, Templates, and Sessions CS 370 SE Practicum, Cengiz Günay (Some slides courtesy of Eugene Agichtein and the Internets) CS 370, Günay (Emory) Django Views/Templates Spring 2014 1 / 7 Agenda

More information