views

Redirect from Generic View DetailView in Django

孤者浪人 提交于 2019-12-18 12:54:16
问题 I'm using Django's class based DetailView generic view to look up an object for display. Under certain circumstances, rather than displaying the object, I wish to back out and issue a HTTP rediect instead. I can't see how I go about doing this. It's for when a user hits an object in my app, but without using the canonical URL. So, for example, on StackOverflow URLs take the form: http://stackoverflow.com/<content_type>/<pk>/<seo_friendly_slug> eg: http://stackoverflow.com/questions/5661806

How to render a view to a string?

大兔子大兔子 提交于 2019-12-18 09:25:25
问题 I want to render a specific view in a sailsjs controller/action which should be sent out as email. I have the following sample action: function registerAction(req, res) { // handle user registration // email user sendEmail({ to: newUser.email, subject: "Welcome", text: /* VIEW RENDER HERE */ }); // render view to the user return res.view({ user: newUser }); } How can I render a view-template with the tools sailsjs provides so that I don't need to hardcode an email text or use other libraries?

Connect Two XIBs To One ViewController

断了今生、忘了曾经 提交于 2019-12-18 07:18:00
问题 I am, in all basics, wanting to have a view for iPhones, and one for iPads. However, I want to use the same view controllers for both of them, since they are the same thing, just optimized for each device. I know it's possible to do this, because it is a universal app and the default views for a universal project include one main view for iPhones, and one main view for iPads. However, they're implemented automatically and so I don't know how to replicate this. So, the jist of this question is

How do you pass or share variables between django views?

不羁岁月 提交于 2019-12-17 16:28:05
问题 I'm kind of lost as to how to do this: I have some chained select boxes, with one select box per view. Each choice should be saved so that a query is built up. At the end, the query should be run. But how do you share state in django? I can pass from view to template, but not template to view and not view to view. Or I'm truly not sure how to do this. Please help! 回答1: There are many ways... in the view to template... put the variables in hidden fields in the forms. So when you "submit" in

Error “The view at '~/Views/Page/home.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>”

跟風遠走 提交于 2019-12-17 16:06:40
问题 I've just installed MVC2 and I've got a view that looks like this <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Home.Master" Inherits="System.Web.Mvc.ViewPage" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Home </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Home</h2> </asp:Content> And the controller is just returning the view. But when I run the page I get this error: System

how to add a code-behind page to a view or partial view

喜你入骨 提交于 2019-12-17 15:44:43
问题 I notice with the latest version of ASP.NET MVC that a View no longer defaults to having code-behind classes. How do I go about adding a code-behind class now to a View or Partial View?? 回答1: How to add a Code-behind page to a Partial View Seems this wasn't particularly tricky, and is quite do-able. This answer worked for a Partial ViewUserControl but the same should apply for a Normal MVC ViewPage as well Add a new Class file with the convention of <view filename & extention>.cs (i.e. view

Class views in Django

人盡茶涼 提交于 2019-12-17 15:38:23
问题 Django view points to a function, which can be a problem if you want to change only a bit of functionality. Yes, I could have million keyword arguments and even more if statements in the function, but I was thinking more of an object oriented approach. For example, I have a page that displays a user. This page is very similar to page that displays a group, but it's still not so similar to just use another data model. Group also has members etc... One way would be to point views to class

Django class based view ListView with form

六眼飞鱼酱① 提交于 2019-12-17 07:18:18
问题 The main view is a simple paginated ListView and I want to add a search form to it. I thought something like this would do the trick: class MyListView(ListView, FormView): form_class = MySearchForm success_url = 'my-sucess-url' model = MyModel # ... But apparently I got it wrong .. and I can't find how to do it in the official documentation. Suggestions ? 回答1: These answers have helped so much to steer me in the right direction. Thank guys. For my implementation I needed a form view that

Calling android dialog without it fading the background

一世执手 提交于 2019-12-17 07:14:22
问题 I have this nice dialog view I set my UserInputDialog class to: <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:id="@+id/nameMessage" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="What is your name Captain?" > </TextView> <EditText android:id="@+id/nameEditText" android:layout

creating my own context processor in django

余生长醉 提交于 2019-12-17 07:12:30
问题 I have come to a point where I need to pass certain variables to all of my views (mostly custom authentication type variables). I was told writing my own context processor was the best way to do this, but I am having some issues. My settings file looks like this TEMPLATE_CONTEXT_PROCESSORS = ( "django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.contrib.messages.context