├── .gitignore ├── README ├── django_monetize ├── __init__.py ├── models.py ├── templates │ └── django_monetize │ │ ├── adsense_ad_unit.html │ │ ├── amazon_custom_link.html │ │ ├── amazon_honor.html │ │ ├── amazon_omakase.html │ │ ├── amazon_search.html │ │ ├── dreamhost_referral.html │ │ ├── paypal_donate.html │ │ └── slicehost_referral.html ├── templatetags │ ├── __init__.py │ └── monetize.py └── views.py ├── monetize_project ├── __init__.py ├── manage.py ├── settings.py ├── templates │ └── sample.html └── urls.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *~ -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | ## Overview of ``django-monetize`` 3 | 4 | ``django-monetize`` a Django application that intends to facilitate optimizing website monetization. It has a two tiered approach to this: 5 | 6 | 1. Supporting a wide variety of monetization options: advertising, amazon affiliates, donations and custom made ads. 7 | 8 | 2. Allow a high degree of context-based targeting and customization. 9 | 10 | Lets give some examples of what ``django-monetize`` can do. 11 | 12 | ### A Hypothetical Case Study: Will Larson and His Blog 13 | 14 | In a far away universe, long long ago, there was a blogger and Django developer named Will Larson. He enjoyed blogging very much, but began to wonder why he spent so much time blogging when his blog didn't even cover its hosting fees. Since he used a VPS for hosting, and only got 20-30k pageviews per month he knew any strategy as simply as throwing Google AdSense on his page wasn't going to be sufficient. 15 | 16 | Worse yet, he was well aware that much of his traffic was from programmers and other technological types, and that they were afflicted with a blight called ad... ad... well, whatever it was called, they never even noticed ads on most pages. 17 | 18 | However, he knew that these tech types liked to purchase technical books, and that also that some individuals might even appreciate particularly indepth tutorials enough to donate a few coins his way. 19 | 20 | The problem was that he wanted to advertise different books for different topics, and only wanted to ask for donations for particularly long works. He was very, very sad. 21 | 22 | Thankfully, one day he found a leprechaun in the bushes nearby his home. The leprechaun offered him one wish, and he wished for riches. The wise leprechaun knew if he gave Will a fortune, he might not be wise enough to invest it in the turmultuous stock market, and instead he gave him a gift that would allow him to reap riches for years to come: ``django-monetize``. 23 | 24 | Using ``django-monetize``, Will was able to do some amazing things. He was already tagging his contents, and was able to display different monetization techniques depending on the tag for the current content being displayed. For articles in a series about PyObjC, he was able to display a donation box pleading for relief from his intense poverty for anyone who found his epic tutorial helpful. For blog entries tagged with Django he was able to advertise a custom ad for the Django Book. For blog entries tagged with cooking he was able to just use ad sense, since people who read about cooking might not be the afflicted with the cruel plague of ad blindness. 25 | 26 | Everyone lived happily ever after. 27 | 28 | The end. 29 | 30 | 31 | ## High Level Overview 32 | 33 | TBA 34 | 35 | ## Installation 36 | 37 | 1. Add the ``django_monetize`` to your Python path. Likely your site folder. 38 | 2. Add ``django_monetize`` to your ``INSTALLED_APPS`` setting in your ``settings.py`` file. 39 | 3. ? 40 | 4. Profit. 41 | 42 | ## Configuration 43 | 44 | One of the key focuses of ``django_monetize`` is to support a high degree of targetting. The logic for that targetting is stored in the ``MONETIZE_TARGET`` and ``MONETIZE_DEFAULT`` values in your project's settings.py file. 45 | 46 | For example, consider the simplest situation where you wanted to display AdSense ad units in all monetization slots: 47 | 48 | MONETIZE_DEFAULT = 'django_monetize/adsense_ad_unit.html' 49 | 50 | Now lets say you want to display a link to an Amazon Affiliate's search results page when targetted on a list containing ``django`` (and otherwise default back to an Adsense ad unit): 51 | 52 | MONETIZE_TARGET = { 53 | 'django':['django_monetize/amazon_search.html',('amazon_search_terms','Django books'),('amazon_search_title','Buy some Django books today!')], 54 | } 55 | MONETIZE_DEFAULT = 'django_monetize/adsense_ad_unit.html' 56 | 57 | If you specify a monetization method using a list/tuple instead of a string, then the zeroth value is the template's string, and the remaining values are 2-tuples (or 2-lists) containing a key and a value, which are used to overwrite values in ``MONETIZE_CONTEXT`` for this specfic monetization. 58 | 59 | Now lets say you have three ad slots on your page: 'header','footer', and 'side'. You can customize the contents of each slot for each term. For this example, lets not show any ads by default. 60 | 61 | MONETIZE_TARGET = { 62 | 'django':{ 63 | 'header':'django_monetize/adsense_ad_unit.html', 64 | 'footer':'django_monetize/slicehost_referral.html', 65 | None:'django_monetize/dreamhost_referral.html', 66 | # Value for None specifies value for non-listed slots. 67 | # if you don't specify an ad for a slot, and don't specify 68 | # a value default, then it won't display an ad. 69 | }, 70 | } 71 | MONETIZE_DEFAULT = False 72 | 73 | Specifying an ad you either pass a string with the ads template, or you pass a list (or tuple) where the zeroth object is the template's string and the other objects are parameters for the rendering function. Whether or not a specific monetization option takes parameters varies, so you'll have to consult the documentation (or the source, if documentation is lacking). 74 | 75 | ## Monetizaton Options 76 | 77 | Here are some monetizations that already have built-in support. If you can't find what you're looking for, remember that you can always roll your own! 78 | 79 | ### Amazon Affiliates: Custom Link 80 | 81 | Use this template along with your Amazon Affiliates account to create referral links for arbitrary Amazon URLs. 82 | 83 | Uses the ``amazon_custom_link.html`` template, and requires the ``amazon_affiliates_id``, ``amazon_custom_link_title``, and ``amazon_custom_link_url`` values in the ``MONETIZE_CONTEXT`` dictionary. 84 | 85 | MONETIZE_CONTEXT = { 86 | 'amazon_affiliates_id='yourAffiliatesID', 87 | 'amazon_custom_link_title':'Look at the Kindle!', 88 | 'amazon_custom_link_url':'http://www.amazon.com/etc/etc', 89 | } 90 | MONETIZE_DEFAULT = 'django_monetize/amazon_custom_link.html' 91 | 92 | Is surrounded by a div with CSS class ``amazon_custom_link``. 93 | 94 | ### Amazon Affiliates: Omakase 95 | 96 | Amazon Affiliate's Omakase widget (Japanese for 'leave it to us') creates and displays a banner that is targeted for your page's content, without you doing any work. 97 | 98 | It requires one settings in the ``MONETIZE_CONTENT`` dictionary: ``amazon_affiliates_id``, and uses the ``django_monetize/amazon_omakase.html`` template. 99 | 100 | Example: 101 | 102 | MONETIZE_CONTEXT = { 103 | 'amazon_affiliates_id':'yourAffiliatesID', 104 | } 105 | # use default 728 width by 90 height values 106 | MONETIZE_DEFAULT = 'django_monetize/amazon_omakase.html' 107 | # You can customize width/height, but must be one of these pairs: 108 | # 120x600, 120x240, 160x600, 180x150, 468x60, 300x250, 600x520 109 | MONETIZE_DEFAULT = ['django_monetize/amazon_omakase.html',120,600] 110 | 111 | Surrounded by div with CSS class ``amazon_makase``. 112 | 113 | 114 | ### Amazon Affiliates: Search Links 115 | 116 | For an Amazon Affiliate link to a search of Amazon's offerings. 117 | 118 | Uses the ``django_monetize/amazon_search.html`` template, and in the ``MONETIZE_CONTEXT`` dictionary it requires values ``amazon_affiliates_id``, ``amazon_search_terms`` and ``amazon_search_title``. 119 | 120 | Example: 121 | 122 | MONETIZE_CONTEXT = { 123 | 'amazon_affiliates_id':'my_tracking_id', 124 | 'amazon_search_terms':'Django book', 125 | 'amazon_search_title':'Buy Django books on Amazon.com!', 126 | } 127 | MONETIZE_DEFAULT = "django_monetize/amazon_search.html" 128 | 129 | Is surrounded by a div with CSS class ``amazon_search``. 130 | 131 | ### Amazon Honor System 132 | 133 | [Amazon Honor System](http://zme.amazon.com/) allows easy donations. 134 | 135 | In the ``MONETIZE_CONTEXT`` dict in your ``settings.py`` file you'll need to specify your paypage url as the value for key ``amazon_paypage``. 136 | 137 | Specify ``django_monetize/amazon_honor.html`` as the template to use the default Amazon honor request. 138 | 139 | Example: 140 | 141 | MONETIZE_CONTEXT = { 142 | 'amazon_paypage':'http://www.amazon.com/pagepage/some-random-has/' 143 | } 144 | MONETIZE_DEFAULT = "django_monetize/amazon_honor.html" 145 | 146 | Surrounded by div with CSS class ``amazon_donate``. 147 | 148 | ### Dreamhost Referrals 149 | 150 | You can use Dreamhost referrals as a monetization option as well. At least theoretically. If you have no shame. And live life with a sadistic streak. 151 | 152 | Uses the ``django_monetize/dreamhost_referral.html`` template. But... well, you'll see. You may want to rewrite it. 153 | 154 | Requires the ``dreamhost_referral_code`` value in the ``MONETIZE_CONTEXT`` dictionary. 155 | 156 | Example: 157 | 158 | MONETIZE_CONTEXT = { 159 | 'dreamhost_referral_code':'123456', 160 | } 161 | MONETIZE_DEFAULT = "django_monetize/dreamhost_referral.html" 162 | 163 | Is wrapped in a div with the ``dreamhost_referral`` CSS class. 164 | 165 | ### Google Adsense: Ad Unit 166 | 167 | Use this monetization option to display one unit of Google ads (not a link box). 168 | 169 | Uses the template ``django_monetize/adsense_ad_unit.html``. 170 | 171 | Requires the ``adsense_ad_unit_client``, ``adsense_ad_unit_slot``, ``adsense_ad_width``, and ``adsense_ad_height`` values in the ``MONETIZE_CONTEXT`` dictionary. 172 | 173 | Example: 174 | 175 | MONETIZE_CONTEXT = { 176 | 'adsense_ad_unit_client':'ad client id', 177 | 'adsense_ad_unit_slot':'ad unit slot', 178 | 'adsense_ad_unit_width':336, 179 | 'adsense_ad_unit_height':280, 180 | } 181 | MONETIZE_DEFAULT = "django_monetize/adsense_ad_unit.html`` 182 | 183 | ### Paypal Donations 184 | 185 | If you have a [PayPal](http://www.paypal.com) account, another option for monetization is using PayPal donations. 186 | 187 | In your settings.py's ``MONETIZE_CONTEXT`` dict you'll need to specify a handful of values to use this option: ``paypal_business``, ``paypal_item_name``, ``paypal_currency_code``, ``paypal_tax``, ``paypal_lc``, ``paypal_bn``, and ``paypal_image``. The value ``paypal_amount`` is optional, and may be used to specify the size of the donation, otherwise the amount is up to the donator. 188 | 189 | It uses the ``django_monetize/paypal_donate.html`` template. 190 | 191 | Example: 192 | 193 | MONETIZE_CONTEXT = { 194 | 'paypal_business':'your_paypal_account@gmail.com', 195 | 'paypal_item_name':'My Awesome Website', 196 | 'paypal_currency_code':'USD', 197 | 'paypal_amount': '5.00', # optional 198 | 'paypal_tax':'0', 199 | 'paypal_lc':'US', 200 | 'paypal_bn':'PP-DonationsBF', 201 | 'paypal_image':'http://www.paypal.com/en_US/i/btn/btn_donate_LG.gif' 202 | } 203 | MONETIZE_DEFAULT = "django_monetize/paypal_donate.html" 204 | 205 | Surrounded by div with CSS class ``paypal_donate``. 206 | 207 | ### SliceHost Referals 208 | 209 | For those of us using SliceHost, we know there isn't a better VPS on the planet. Since we like to share that joy, sometimes we like send a few referrals their way. 210 | 211 | Uses the ``django_monetize/slicehost_referral.html`` template. 212 | 213 | Requires the ``slicehost_referral_id`` value in the ``MONETIZE_CONTEXT`` dictionary. It is the id at the end of the link if login to your SliceHost account, go to the ``Acount`` section, and then click on ``Referrals``. (The number after the question mark near the end of the url.) 214 | 215 | Example: 216 | 217 | MONETIZE_CONTEXT = { 218 | 'slicehost_referral_id':'123456789', 219 | } 220 | MONTIZE_DEFAULT = "slicehost_referral.html" 221 | 222 | Is surrounded by a div with the CSS class ``slicehost_referral``. 223 | 224 | -------------------------------------------------------------------------------- /django_monetize/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lethain/django-monetize/cb130175a46c317b2bf8bb6caa3974583ff7e9ad/django_monetize/__init__.py -------------------------------------------------------------------------------- /django_monetize/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /django_monetize/templates/django_monetize/adsense_ad_unit.html: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /django_monetize/templates/django_monetize/amazon_custom_link.html: -------------------------------------------------------------------------------- 1 |
3 | If you appreciate the content,please consider donating. Creativity burns calories faster than you'd believe. 4 |
5 |3 | Sign up for Dreamhost! Worth every bit of $10 a month. Excessively large quantities of bandwidth and disk storage. Occasional uptime! 4 |
5 |3 | You won't find better VPS hosting than SliceHost. Get an account today! 4 |
5 |Some content.
11 | {% monetize_slot "bottom" request.META.HTTP_USER_AGENT %} 12 | 13 | 16 | 17 | 18 | In the first of those examples we are targeting monetization using an object's tags, and in the second example we are targeting monetization using a request's user agent. 19 | 20 | The third example (at the "side bar" slot) shows passing an arbitrary number of dictionaries, lists and strings into the slot. Excluding the first parameter, which is the name of the slot, they will be systematically searched for values specified in your ``MONETIZE_TARGET`` dictionary. 21 | 22 | The first value matching a targeting value will be used. Values will be matched as follows: 23 | 24 | 1. It will sensibly match against the contents of lists, tuples 25 | and dictionaries, but **all other objects will be matched by 26 | using the value returned by their __repr__ method**. 27 | 28 | 2. **String/Unicode objects** will be matched against the keys 29 | in the ``MONETIZE_TARGET`` dictionary. (If you specify "django" 30 | it will check for a key named "django" and use its targeting logic.) 31 | 32 | 3. **Lists/Tuples** will be stepped through, with each value being checked against the keys in the ``MONETIZE_TARGET`` dictionary. 33 | 34 | 4. **Dictionaries** will be replaced by a list of their items, which will then be processed normally as a list. 35 | 36 | 5. The **None** value will be ignored. 37 | 38 | 6. If there are no matches, then the system will fall back onto the ``MONETIZE_DEFAULT`` value. If ``MONETIZE_DEFAULT`` is not specified (or its value is NONE) then it will simply return an empty string. 39 | 40 | 41 | Don't be fooled by the above example: ``django_monetize`` doesn't help you inject ``request`` into your templates' context; you'll have to handle that yourself. 42 | """ 43 | 44 | from django import template 45 | from django.conf import settings 46 | 47 | register = template.Library() 48 | 49 | @register.tag(name="monetize_slot") 50 | def monetize_slot(parser, token): 51 | 'Template tag for displaying a monetization option in a slot.' 52 | lst = token.split_contents() 53 | return MonetizeSlotNode(*lst[1:]) 54 | 55 | 56 | class MonetizeSlotNode(template.Node): 57 | def __init__(self, *vals): 58 | if len(vals) > 0: 59 | self.slot = vals[0].strip('"') 60 | self.params = vals[1:] 61 | else: 62 | self.slot = None 63 | self.params = () 64 | 65 | def render(self,context): 66 | 'Apply targeting and render monetization option for value/slot combo.' 67 | target = self.acquire_target(self.params,context) 68 | return self.target(target,self.slot,context) 69 | 70 | def acquire_target(self,params,context): 71 | 'Go through parameters and try to find a valid targeting parameter.' 72 | logic_dict = getattr(settings,'MONETIZE_TARGET',{}) 73 | 74 | for param in params: 75 | try: 76 | param = template.resolve_variable(param,context) 77 | except template.VariableDoesNotExist: 78 | pass 79 | if type(param) == dict: 80 | param = dict.iteritems() 81 | 82 | if hasattr(param,'__iter__'): 83 | for x in param: 84 | x = unicode(x) 85 | if logic_dict.has_key(x): 86 | return x 87 | else: 88 | param = unicode(param) 89 | if logic_dict.has_key(param): 90 | return param 91 | 92 | return None 93 | 94 | def target(self,value,slot,context): 95 | ''' 96 | Returns the rendered text for 'value'. 'value' should be 97 | the output of the 'choose_target' method. 98 | 99 | Also be aware the distinction being made between 100 | False and None. None refers to the concept of using 101 | the default monetization option, while False refers 102 | to not using a monetization option. 103 | ''' 104 | logic_dict = getattr(settings,'MONETIZE_TARGET',{}) 105 | if logic_dict.has_key(value): 106 | logic = logic_dict[value] 107 | else: 108 | logic = getattr(settings,"MONETIZE_DEFAULT",False) 109 | 110 | # Deconstruct slot specific logic from dict. 111 | if type(logic) == dict: 112 | if logic.has_key(slot): 113 | # Check for slot specific logic. 114 | logic = logic[slot] 115 | elif logic.has_key(None): 116 | # Check for value specific default logic. 117 | logic = logic[None] 118 | else: 119 | # Otherwise display nothing. 120 | logic = False 121 | 122 | if type(logic) == tuple or type(logic) == list: 123 | context_dict = getattr(settings,'MONETIZE_CONTEXT',{}).copy() 124 | if len(logic) == 0: 125 | logic = False 126 | else: 127 | # load extra context from list 128 | for key,val in logic[1:]: 129 | context_dict[key] = val 130 | logic = logic[0] 131 | else: 132 | context_dict = getattr(settings,'MONETIZE_CONTEXT',{}) 133 | 134 | # At this point ``logic`` should be a string for a template, or False 135 | if logic == False: 136 | # False means no monetization option, so return empty string. 137 | rendered = u"" 138 | else: 139 | new_context = template.Context(context_dict,context.autoescape) 140 | t = template.loader.get_template(logic) 141 | rendered = t.render(new_context) 142 | 143 | return rendered 144 | -------------------------------------------------------------------------------- /django_monetize/views.py: -------------------------------------------------------------------------------- 1 | # Create your views here. 2 | -------------------------------------------------------------------------------- /monetize_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lethain/django-monetize/cb130175a46c317b2bf8bb6caa3974583ff7e9ad/monetize_project/__init__.py -------------------------------------------------------------------------------- /monetize_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from django.core.management import execute_manager 3 | try: 4 | import settings # Assumed to be in the same directory. 5 | except ImportError: 6 | import sys 7 | sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) 8 | sys.exit(1) 9 | 10 | if __name__ == "__main__": 11 | execute_manager(settings) 12 | -------------------------------------------------------------------------------- /monetize_project/settings.py: -------------------------------------------------------------------------------- 1 | # Django settings for monetize_project project. 2 | 3 | import os 4 | ROOT_PATH = os.path.dirname(__file__) 5 | 6 | 7 | 8 | MONETIZE_CONTEXT = { 9 | # Amazon Honor System 10 | 'amazon_paypage':'url', 11 | 12 | # Amazon Affilliates (used for all others) 13 | 'amazon_affiliates_id':'affiliates_id', 14 | 15 | # Amazon Affiliates: Custom Links 16 | 'amazon_custom_link_title':'Look at the Kindle!', 17 | 'amazon_custom_link_url':'http://www.amazon.com/etc/etc', 18 | 19 | # Amazon Affilliates: Omakase 20 | 'amazon_omakase_width':'728', 21 | 'amazon_omakase_height':'90', 22 | 23 | # Amazon Affiliates: Search 24 | 'amazon_search_terms':"Django book", 25 | 'amazon_search_title':"Search for Django books!", 26 | 27 | # Slicehost Referrals 28 | 'slicehost_referral_id':'slicehost referal id', 29 | 30 | # Dreamhost Referrals 31 | 'dreamhost_referral_code':'dreamhost referal id', 32 | 33 | # Google AdSense: Ad Unit 34 | 'adsense_ad_unit_client':'ad unit client', 35 | 'adsense_ad_unit_slot':'ad slot id', 36 | 'adsense_ad_unit_width':'336', 37 | 'adsense_ad_unit_height':'280', 38 | 39 | # Paypal 40 | 'paypal_business':'email', 41 | 'paypal_item_name':'name', 42 | 'paypal_currency_code':'USD', 43 | 'paypal_amount':None, # '5.00', 44 | 'paypal_tax':'0', 45 | 'paypal_lc':'US', 46 | 'paypal_bn':'PP-DonationsBF', 47 | 'paypal_image':'http://www.paypal.com/en_US/i/btn/btn_donate_LG.gif' 48 | } 49 | 50 | MONETIZE_TARGET = { 51 | 'django':'django_monetize/amazon_search.html', 52 | 'python':'django_monetize/paypal_donate.html', 53 | 54 | } 55 | 56 | MONETIZE_DEFAULT = 'django_monetize/slicehost_referral.html' 57 | 58 | DEBUG = True 59 | TEMPLATE_DEBUG = DEBUG 60 | 61 | ADMINS = ( 62 | # ('Your Name', 'your_email@domain.com'), 63 | ) 64 | 65 | MANAGERS = ADMINS 66 | 67 | DATABASE_ENGINE = '' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 68 | DATABASE_NAME = '' # Or path to database file if using sqlite3. 69 | DATABASE_USER = '' # Not used with sqlite3. 70 | DATABASE_PASSWORD = '' # Not used with sqlite3. 71 | DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. 72 | DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. 73 | 74 | # Local time zone for this installation. Choices can be found here: 75 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name 76 | # although not all choices may be available on all operating systems. 77 | # If running in a Windows environment this must be set to the same as your 78 | # system time zone. 79 | TIME_ZONE = 'America/Chicago' 80 | 81 | # Language code for this installation. All choices can be found here: 82 | # http://www.i18nguy.com/unicode/language-identifiers.html 83 | LANGUAGE_CODE = 'en-us' 84 | 85 | SITE_ID = 1 86 | 87 | # If you set this to False, Django will make some optimizations so as not 88 | # to load the internationalization machinery. 89 | USE_I18N = True 90 | 91 | # Absolute path to the directory that holds media. 92 | # Example: "/home/media/media.lawrence.com/" 93 | MEDIA_ROOT = '' 94 | 95 | # URL that handles the media served from MEDIA_ROOT. Make sure to use a 96 | # trailing slash if there is a path component (optional in other cases). 97 | # Examples: "http://media.lawrence.com", "http://example.com/media/" 98 | MEDIA_URL = '' 99 | 100 | # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a 101 | # trailing slash. 102 | # Examples: "http://foo.com/media/", "/media/". 103 | ADMIN_MEDIA_PREFIX = '/media/' 104 | 105 | # Make this unique, and don't share it with anybody. 106 | SECRET_KEY = '#==th24xb_-*gpf-ovp@91cb+atycl-rlwc(jnim-j5erag^6t' 107 | 108 | # List of callables that know how to import templates from various sources. 109 | TEMPLATE_LOADERS = ( 110 | 'django.template.loaders.filesystem.load_template_source', 111 | 'django.template.loaders.app_directories.load_template_source', 112 | # 'django.template.loaders.eggs.load_template_source', 113 | ) 114 | 115 | MIDDLEWARE_CLASSES = ( 116 | 'django.middleware.common.CommonMiddleware', 117 | 'django.contrib.sessions.middleware.SessionMiddleware', 118 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 119 | ) 120 | 121 | ROOT_URLCONF = 'monetize_project.urls' 122 | 123 | TEMPLATE_DIRS = ( 124 | # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 125 | # Always use forward slashes, even on Windows. 126 | # Don't forget to use absolute paths, not relative paths. 127 | os.path.join(ROOT_PATH, 'templates'), 128 | ) 129 | 130 | INSTALLED_APPS = ( 131 | 'django_monetize', 132 | 'django.contrib.auth', 133 | 'django.contrib.contenttypes', 134 | 'django.contrib.sessions', 135 | 'django.contrib.sites', 136 | ) 137 | -------------------------------------------------------------------------------- /monetize_project/templates/sample.html: -------------------------------------------------------------------------------- 1 | {% load monetize %} 2 | 3 | 4 | 5 |^^^ Header slot. Some content. VVV footer slot.
15 | 16 |Footer gets tags: {{ tags }}
17 | 18 | {% monetize_slot "footer" tags %} 19 | 20 |And finally, a slot without a slot name.
30 | 31 | {% monetize_slot %} 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /monetize_project/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls.defaults import * 2 | 3 | tags = ['python','ruby','django'] 4 | 5 | urlpatterns = patterns('django.views.generic.simple', 6 | (r'^$','direct_to_template', {'template': 'sample.html','extra_context':{'tags':tags},}), 7 | ) 8 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from setuptools import setup, find_packages 3 | 4 | f = open(os.path.join(os.path.dirname(__file__), 'README')) 5 | readme = f.read() 6 | f.close() 7 | 8 | setup( 9 | name='django-monetize', 10 | version="1.0.0", 11 | description='A pluggable Django application for delivering highly targeted advertisement.', 12 | long_description=readme, 13 | author='Will Larson', 14 | author_email='lethain@gmail.com', 15 | url='http://github.com/lethain/django-monetize', 16 | packages=find_packages(exclude=['monetize_project']), 17 | package_data = { 18 | '': [ 19 | 'django_monetize/templates/*/*.html', 20 | ], 21 | }, 22 | classifiers=[ 23 | 'Development Status :: 5 - Production', 24 | 'Environment :: Web Environment', 25 | 'Intended Audience :: Developers', 26 | 'License :: OSI Approved :: MIT License', 27 | 'Operating System :: OS Independent', 28 | 'Programming Language :: Python', 29 | 'Framework :: Django', 30 | ], 31 | ) 32 | --------------------------------------------------------------------------------