from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
from django.template import Library, Context, loader

register = Library()

@register.simple_tag( takes_context = True )
def jfu( 
        context, 
        template_name = 'jfu/upload_form.html', 
        upload_handler_name = 'jfu_upload' 
    ):
    """
    Displays a form for uploading files using jQuery File Upload.

    A user may supply both a custom template or a custom upload-handling URL
    name by supplying values for template_name and upload_handler_name
    respectively.
    """
    context.update( { 
        'JQ_OPEN'  : '{%',
        'JQ_CLOSE' : '%}',
        'upload_handler_url': reverse( upload_handler_name ),
    } )

    # Use the request context variable, injected
    # by django.core.context_processors.request
    # to generate the CSRF token.
    context.update( csrf( context.get('request') ) )

    t = loader.get_template( template_name )

    return t.render( Context( context ) )

from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
from django.template import Library, Context, loader

register = Library()

@register.simple_tag( takes_context = True )
def jfu( 
        context, 
        template_name = 'jfu/upload_form.html', 
        upload_handler_name = 'jfu_upload',
        *args, **kwargs
    ):
    """
    Displays a form for uploading files using jQuery File Upload.

    A user may supply both a custom template or a custom upload-handling URL
    name by supplying values for template_name and upload_handler_name
    respectively.
    """
    context.update( { 
        'JQ_OPEN'  : '{%',
        'JQ_CLOSE' : '%}',
        'upload_handler_url': reverse( upload_handler_name, kwargs=kwargs, args=args ),
    } )

    # Use the request context variable, injected
    # by django.core.context_processors.request
    # to generate the CSRF token.
    context.update( csrf( context.get('request') ) )

    t = loader.get_template( template_name )

    return t.render( Context( context ) )

Allow args and kwargs to upload_handler_name
Allow args and kwargs to upload_handler_name

Now can use args and kwargs for reverse url. Example in template:
{% jfu 'core/core_fileuploader.html' 'core_upload' object_id=1 content_type_str='app.model' %}
  from django.core.context_processors import csrf
  from django.core.urlresolvers import reverse
  from django.template import Library, Context, loader
  
  register = Library()
  
  @register.simple_tag( takes_context = True )
  def jfu( 
          context, 
          template_name = 'jfu/upload_form.html', 
-         upload_handler_name = 'jfu_upload' 
+         upload_handler_name = 'jfu_upload',
+         *args, **kwargs
      ):
      """
      Displays a form for uploading files using jQuery File Upload.
  
      A user may supply both a custom template or a custom upload-handling URL
      name by supplying values for template_name and upload_handler_name
      respectively.
      """
      context.update( { 
          'JQ_OPEN'  : '{%',
          'JQ_CLOSE' : '%}',
-         'upload_handler_url': reverse( upload_handler_name ),
+         'upload_handler_url': reverse( upload_handler_name, kwargs=kwargs, args=args ),
      } )
  
      # Use the request context variable, injected
      # by django.core.context_processors.request
      # to generate the CSRF token.
      context.update( csrf( context.get('request') ) )
  
      t = loader.get_template( template_name )
  
      return t.render( Context( context ) )
  
Allow args and kwargs to upload_handler_name
## Code Before:
from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
from django.template import Library, Context, loader

register = Library()

@register.simple_tag( takes_context = True )
def jfu( 
        context, 
        template_name = 'jfu/upload_form.html', 
        upload_handler_name = 'jfu_upload' 
    ):
    """
    Displays a form for uploading files using jQuery File Upload.

    A user may supply both a custom template or a custom upload-handling URL
    name by supplying values for template_name and upload_handler_name
    respectively.
    """
    context.update( { 
        'JQ_OPEN'  : '{%',
        'JQ_CLOSE' : '%}',
        'upload_handler_url': reverse( upload_handler_name ),
    } )

    # Use the request context variable, injected
    # by django.core.context_processors.request
    # to generate the CSRF token.
    context.update( csrf( context.get('request') ) )

    t = loader.get_template( template_name )

    return t.render( Context( context ) )

## Instruction:
Allow args and kwargs to upload_handler_name
## Code After:
from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
from django.template import Library, Context, loader

register = Library()

@register.simple_tag( takes_context = True )
def jfu( 
        context, 
        template_name = 'jfu/upload_form.html', 
        upload_handler_name = 'jfu_upload',
        *args, **kwargs
    ):
    """
    Displays a form for uploading files using jQuery File Upload.

    A user may supply both a custom template or a custom upload-handling URL
    name by supplying values for template_name and upload_handler_name
    respectively.
    """
    context.update( { 
        'JQ_OPEN'  : '{%',
        'JQ_CLOSE' : '%}',
        'upload_handler_url': reverse( upload_handler_name, kwargs=kwargs, args=args ),
    } )

    # Use the request context variable, injected
    # by django.core.context_processors.request
    # to generate the CSRF token.
    context.update( csrf( context.get('request') ) )

    t = loader.get_template( template_name )

    return t.render( Context( context ) )
