django-views

How to export queryset in Django 1.7 to xls file?

守給你的承諾、 提交于 2019-12-13 18:39:56
问题 I using Django 1.7.1 with Python 3.4. I would like to export search results to Excel file. I have this function in view.py def car_list(request): page = request.GET.get('page') search = request.GET.get('search') if search is None: cars= Car.objects.filter(plate__isnull = False ).order_by('-created_date') else: cars= Car.objects.filter(plate__contains = search ).order_by('-created_date') paginator = Paginator(cars, 100) # Show 100 contacts per page try: cars= paginator.page(page) except

django-userena views.py and user registration issues

╄→гoц情女王★ 提交于 2019-12-13 18:06:41
问题 django-userena does not have a views.py file. It uses instead html files, i would like to use this views.py instead of the html files, because i want to add some other features, like a file uploader. I'm having a hard time implementing apps like django-jquery-file-upload The second question is how to activate the user's account automatically after that he confirms his email. 回答1: The first thing that i would like to do is get rid of the html files and replace them with this views.py, django

Django is_ajax history back

♀尐吖头ヾ 提交于 2019-12-13 17:06:42
问题 I wrote a Django view that responses ether a text/html or a application/json depending on request.is_ajax() . So far so good, but when I use my browsers history buttons, I end up getting a JSON response rather than the HTML. I can't figure out the problem. It's true an jQuery ajax request is getting the same url after the page was loaded, but that shouldn't end up in the history, or should it? Thanks, Joe 回答1: If you send different content depending on request.is_ajax() , you need to send

Django pass variable into template

萝らか妹 提交于 2019-12-13 16:40:33
问题 Hi thank you for helping, I'm poor in coding. To point: I'm doing a Django project that pass data form data-base to front-end; but right now i can't even pass anything views of Django into templates, I suspect i'm passing the wrong variable types; please do comment on your thought. This is my code on views.py: from django.shortcuts import render def index (requset): return render(requset,'myapp/index.html') # link to be able open frountend def testdex(requset): text = "hello world" context ={

Django Rest Framework: Unclear error message

穿精又带淫゛_ 提交于 2019-12-13 15:36:13
问题 my views.py : class user_password(generics.UpdateAPIView): authentication_classes = ([JSONWebTokenAuthentication]) serializer_class = user_password_serializer def get_queryset(self): return User.objects.get(id=self.request.user.id) But I'm getting this when running it: AssertionError: Expected view user_password to be called with a URL keyword argument named "pk". Fix your URL conf, or set the .lookup_field attribute on the view correctly. I know the serializer is okay because when I use a

Django: Downloading uploaded files

我的梦境 提交于 2019-12-13 12:44:52
问题 I have form details in this question Django: Adding files to a form gives multiple argument error How to download the uploaded file. When i go to edit view of the form, i can see uploaded file url, but its not downloading. What setting to be changed for development and production mode? Error upon clicking link: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/media/Certificate.docx Using the URLconf defined in tiktant.urls, Django tried these URL patterns, in this

Page not found (404)

不想你离开。 提交于 2019-12-13 12:28:20
问题 Error: Request Method: GET Request URL: http://192.168.100.10/accounts/profile/ Using the URLconf defined in urls, Django tried these URL patterns, in this order: ^collect/ ^member/ ^accounts/login/$ ^ ^$ ^ ^contact/$ ^ ^privacy-statement/$ ^logout/$ [name='logout'] ^data-admin/doc/ ^accounts/password/reset/$ ^accounts/password/reset/done/$ ^accounts/password/reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$ ^accounts/password/done/$ ^media/(?P<path>.*)$ The current URL, accounts/profile/, didn

Bootstrap3 tabs in Django

穿精又带淫゛_ 提交于 2019-12-13 12:19:33
问题 I want to implement Bootstrap3 tabs in my app, which displays school data by state. So if you go to example.com/ma/ you will see information for the state of Massachusetts and tabs to sort by grade level. I am already using the queryset to filter by state so that on example.com/ma/ only "ma" results appear. And I can show ALL data in one of the tabs, but can't filter it out for multiple tabs. To keep it simple, I just want to do tabs for "All" and "High School" here. Here is my models.py :

Django Primary Key: badly formed hexadecimal UUID string

做~自己de王妃 提交于 2019-12-13 12:14:04
问题 I'm trying to use UUIDField as a primary key for a model. I'm using CreateView for creating objects for this model. Anytime I browse to the url for creating one of the objects I get the error: badly formed hexadecimal UUID string The stack trace shows the error occurs here, where value is created: /home/conor/django/venv2/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py in get_db_prep_value return name, path, args, kwargs def get_internal_type(self): return "UUIDField"

send email to bcc and cc in django

此生再无相见时 提交于 2019-12-13 11:53:17
问题 views.py if 'send_email' in request.POST: subject, from_email, to = 'Parent Incident Notification',user.email, person.parent_email html_content = render_to_string('incident/print.html',{'person':person, 'report':report, }) text_content = strip_tags(html_content) msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [to]) msg.attach_alternative(html_content, "text/html") msg.send() The above is the view to send email.By that way i can send the html content along with