Reputation:
i am currently facing problem on opening html page using django although i have tried to figure out on the url.py, view.py, and the html page. My code is stated below:
batterycurrent.py under views folder
from __future__ import absolute_import
from __future__ import unicode_literals
from django.core.files.storage import default_storage
from django.core.urlresolvers import reverse_lazy
from django.http import HttpResponseRedirect
from django.utils import timezone
from django.views.generic import FormView, TemplateView
from sendfile import sendfile
import os.path
from .mixin import AjaxTemplateMixin, PermissionRequiredMixin, PageTitleMixin
from ..forms import DiagnosticsForm
from ..tasks import dump_diagnostics
from django.shortcuts import render
class DiagnosticMixin(PageTitleMixin, PermissionRequiredMixin):
permission_required = ['system.view_log_files']
page_title = 'Diagnostics'
form_class = DiagnosticsForm
class BatteryCurrentView(DiagnosticMixin,FormView):
template_name = 'system/batterycurrent.html'
def batterycurrent(request):
return render(request, 'system/batterycurrent.html')
url.py
from __future__ import absolute_import
from __future__ import unicode_literals
from collections import OrderedDict
from django.conf.urls import url
from django.core.urlresolvers import reverse_lazy
from .views import BatteryCurrentView
sub_urlpatterns['diagnostic'] = [
url(r'^diagnostics$', DiagnosticView.as_view(), name='diagnostic'),
url(r'^diagnostics/download', DiagnosticDownloadView.as_view(), name='diagnostic-download'),
url(r'^diagnostics/batterycurrent', BatteryCurrentView.as_view(), name='batterycurrent'),
]
**the batterycurrent.html is within diagnostic.html.
batterycurrent.html(Template (the html is in the system folder)
<li><a href="{% url 'system:batterycurrent' %}">Battery Current Vs Timestamp</a></li>
when i started to execute the code, the errors appeared
i) importError batterycurrentView couldn't be imported
ii)Reverse for 'batterycurrent' with arguments '()' and keyword arguments '{}'
not found. 0 pattern(s) tried: []
Please guide me on this
Upvotes: 0
Views: 1433
Reputation: 9235
Try it again after adding some context in the view, or leave it empty.
def batterycurrent(request):
return render (request, template, {})
Upvotes: 0
Reputation: 6650
Seems like the problem is in import the module in url.py file.
If you have created BatteryCurrentView module inside the batterycurrent.py and your url.py
file in the different folder then you need to import your module through the name of the folder with the file name.
So Your file is inside the view folder then you should use
from views.batterycurrent import BatteryCurrentView
And if in case your file url.py
resides in the same folder inside view then you need to just import module like this:
from .batterycurrent import BatteryCurrentView
Upvotes: 0
Reputation: 599490
You haven't provided your full app layout so this is a bit hard to answer, but it sounds like you have a views folder containing a file "batterycurrent.py", which in turn contains your view BatteryCurrentView.
If so, as well as ensuring that you have an (empty) __init__.py
file in that directory, you urls.py needs to import the view from the module it is in:
from views.batterycurrent import BatteryCurrentView
Also, I don't understand what you are doing with sub_urlpatterns
in that file. You don't define that dictionary anywhere; but in any case, the patterns must be in a list called just urlpatterns
.
Finally, ensure that that file is actually called urls.py, not url.py.
Upvotes: 1