i new in django
. want pass log file name template view log file name fuze-2015-04-28-08-07-34_28744226_30892878.log
. when click on tag in html gives me error page not found
error noreversematch @ / reverse 'parselog' arguments '('fuze-2015-04-27-00-42-55.log',)' , keyword arguments '{}' not found. 1 pattern(s) tried: ['parselog/(?p[-\w]+)/$']
error during template rendering
in template c:\fuzelog\fuzelog\templates\index.html, error @ line 61 reverse 'parselog' arguments '('fuze-2015-04-27-00-42-55.log',)' , keyword arguments '{}' not found. 1 pattern(s) tried: ['parselog/(?p[-\w]+)/$']
61:{{ logfile }}
index.html
<!doctype html> <html lang="en"> <head> </head> <body> <div class="row"> <div class="col-xs-6 col-sm-4" style='overflow:auto; width:400px; height:500px;'> {% logfile in logfiles %} <a href="{% url 'parselog' logfile %}">{{ logfile }}</a> <br> {% endfor %} </div> </div> </body> </html>
urls.py
from django.conf.urls import patterns, include, url django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # examples: url(r'^$', 'fuzelogapp.views.home', name='home'), url(r'^parselog/(?p<logfile>[-\w]+)/$', 'fuzelogapp.views.parselog', name='parselog'), url(r'^admin/', include(admin.site.urls)), )
view.py
def home(request): try: osname = platform.system() print osname if osname == "windows": path="c:\\users\\ish_war\\appdata\\local\\fuzebox\\logs" # insert path directory logfile_list =os.listdir(path) else: pass except ioerror e: print "i/o error({0}): {1}".format(e.errno, e.strerror) return render_to_response('index.html',{'osname':"i/o error({0}): {1}".format(e.errno, e.strerror)},context_instance=requestcontext(request)) return render_to_response('index.html',{'osname':osname ,'logfiles': logfile_list},context_instance=requestcontext(request)) def parselog(request,logfile): print logfile
use url template tag in index.html, , pass logfile
variable argument
{% logfile in logfiles %} <a href="{% url 'parselog' logfile %}">{{ logfile }}</a> <br> {% endfor %}
in urls.py, need allow '.' in regex:
url(r'^parselog/(?p<logfile>[\w.-]+)/$', 'fuzelogapp.views.parselog', name='parselog'),