custom-routes

Django REST Framework show multiple forms on HTML view

孤人 提交于 2019-12-11 11:34:18
问题 I have a ViewSet using Django REST Framework that has both standard and custom routes. The serializer for each route is different. Example: class UserViewSet(ViewSet): model = User serializer_class = UserSerializer @decorators.detail_route(methods=['put']) def change_password(self, request, pk, *args, **kwargs): serializer = UserChangePasswordSerializer(data=request.data) ... @decorators.detail_route(methods=['put']) def update_prefs(self, request, *args, **kwargs): serializer =

MVC 4: Custom Routes

99封情书 提交于 2019-12-11 08:50:17
问题 I see a lot of problems with MVC routes and I'm having a similar problem getting a route to match a URL. routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //default route routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); routes.MapRoute("Beer", "Beer/{beerid}", new { controller = "Beer", action = "Id", beerid = 0}); routes.MapRoute("Beer", "Beer/{beername}", new { controller = "Beer",

How to make my routes more efficient?

此生再无相见时 提交于 2019-12-11 05:54:59
问题 By making rewrite directives in .htaccess file I write my custom directives. class Route { public $request_url; public $url_args; public $request_method; function __construct() { $this -> request_url = $_SERVER['PATH_INFO']; $this -> url_args = explode('/', substr($_SERVER['PATH_INFO'], 1)); $this -> request_method = $_SERVER['REQUEST_METHOD']; } public function get($url, $callback) { if($this -> request_method == 'GET') { if($url == $this -> request_url){ $callback(); } elseif(strpos($url, '

ASP.NET MVC Routes: How to name an action something completely different than in URL

╄→尐↘猪︶ㄣ 提交于 2019-12-08 11:19:35
问题 This is a continuation of a couple of previous questions I've had. I have a controller called UserController that I'd like to handle actions on two types of objects: User and UserProfile. Among other actions, I'd like to define an Edit action for both of these objects, and within UserController. They'll need to be separate actions, and I don't mind calling them EditUser and EditProfile in the controller , but I'd prefer if the URL's looked like this: http://www.example.com/User/Edit/{userID}

Multiple levels in MVC custom routing

旧街凉风 提交于 2019-12-07 15:50:31
I am trying to build my own little cms. I created an abstract pageBase class that is inherited by Static, Reviews, Articles, News. Each having there own controller methods. My problem is that I need to allow the admin to define his own custom path levels. E.g. news\local\mynewdog or Articles\events\conventions\mycon . So I would like a way to pass an array of strings and also set the custom routing. You can make CMS-style routes seamlessly with a custom RouteBase subclass. public class PageInfo { // VirtualPath should not have a leading slash // example: events/conventions/mycon public string

MVC Custom Route. DataTokens[“Namespaces”] is ignored

点点圈 提交于 2019-12-07 12:27:17
问题 I don't know why while creating a CustomRoute which inherits from Route , the field DataTokens["Namespaces"] is ignored. And I get the error: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter. Here is

global.asax redirecttoroute not working

我怕爱的太早我们不能终老 提交于 2019-12-06 08:42:55
问题 I want to use a custom route in my global.asax with response.redirecttoroute but it is not working. I have the following in my RouteConfig: routes.MapRoute( name: "Error", url: "Error/{action}/{excep}", defaults: new { action = "Index", excep = UrlParameter.Optional } ); And in my global.asax I do the following: Response.RedirectToRoute("Error", new { action="Index", excep=ex.Message }); In my ErrorController I have: public ActionResult Index(string excep) { ViewBag.Exception = excep; return

How to define own routing helpers in rails 3?

ε祈祈猫儿з 提交于 2019-12-06 02:09:38
问题 I use polimorphic_path and it some buggy. This method require some route helper that not defined. How i can define (like regular method) own route helper wich will be used like "model_name_path, model_name_url etc"? 回答1: This solution worked for me. Add this code to the end of config/routes.rb file. Make sure to replace MyApp with your application's name. MyApp::Application.routes.named_routes.module.module_eval do def model_name_path(*args) # Your code here end def model_name_url(*args) #

polymorphic_path for custom collection route

时间秒杀一切 提交于 2019-12-06 02:04:56
问题 I have the following route definition: resources :documents do collection do post :filter end end and the following model structure: class Document < ActiveRecord::Base belongs_to :documentable, :polymorphic => true end class User < ActiveRecord::Base has_many :documents, :as => :documentable end and controller structure: class DocumentsController < ApplicationController def index # not important end def filter # not important end end I can easily in a view say: polymorphic_path([@user,

MVC Custom Route. DataTokens[“Namespaces”] is ignored

南笙酒味 提交于 2019-12-05 19:43:48
I don't know why while creating a CustomRoute which inherits from Route , the field DataTokens["Namespaces"] is ignored. And I get the error: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter. Here is the sample: Application_Start() public static void RegisterRoutes(RouteCollection routes) { //Create