routes

Using variables across Flask routes [duplicate]

谁都会走 提交于 2019-12-19 04:12:48
问题 This question already has answers here : Are global variables thread safe in flask? How do I share data between requests? (2 answers) Closed last year . I am learning Flask and have a question regarding use of variables in the context of routes.For Example, my app.py: from flask import Flask, render_template app = Flask(__name__) @app.route("/index") def index(): a=3 b=4 c=a+b return render_template('index.html',c=c) @app.route("/dif") def dif(): d=c+a return render_template('dif.html',d=d)

Overriding named routes provided by Rails 3 Engines

◇◆丶佛笑我妖孽 提交于 2019-12-18 21:49:51
问题 I am working on a Ruby on Rails 3(.0) application that uses a Rails engine. However, in my local application, I want to override one of the routes provided by the Rails engine. From the engine config/routes.rb: match 'their_named_route' => 'controller#action', :as => 'the_route' From my application config/routes.rb: match 'my_named_route' => 'controller#action', :as => 'the_route' However, when I inspect the routes, both seem to be active (and their route appears to "win", at least within the

CodeIgniter optional parameter

▼魔方 西西 提交于 2019-12-18 19:41:13
问题 I'm trying to use routing in CI to create a signup form signup is re-routed to user/signup But my signup function can contain a paramater: function signup($type = 1) How can I make this optional via routing? I tried $route['signup/?(:num)'] = 'user/signup/$1'; , but when going to /signup I'm getting a 404, only /signup/1/ works. 回答1: The clearest way to express this would probably be to declare both routes: $route['signup'] = "user/signup"; $route['signup/(:num)'] = "user/signup/$1"; 回答2: For

assign null default value for optional query param in route - Play Framework

两盒软妹~` 提交于 2019-12-18 19:31:15
问题 I'm trying to define an optional query parameter that will map to a Long , but will be null when it is not present in the URL: GET /foo controller.Foo.index(id: Long ?= null) ... and I essentially want to check if it was passed in or not: public static Result index(Long id) { if (id == null) {...} ... } However, I'm getting a compilation error: type mismatch; found : Null(null) required: Long Note that implicit conversions are not applicable because they are ambiguous: both method

Dynamic Rails routes based on database models

佐手、 提交于 2019-12-18 13:29:19
问题 So I'm building a Rails site that needs routes based on two different types I have a Language model and a Category model So I need to be able to go to a language route /ruby to see top ruby resources and also go to /books to see top books in all languages I tried routes like this get '/:language', to: "top_voted#language" get '/:category', to: "top_voted#category" the problem with that was the logic could not figure out the difference between the two and caused some conflicts on the back end

Dynamic Rails routes based on database models

有些话、适合烂在心里 提交于 2019-12-18 13:28:28
问题 So I'm building a Rails site that needs routes based on two different types I have a Language model and a Category model So I need to be able to go to a language route /ruby to see top ruby resources and also go to /books to see top books in all languages I tried routes like this get '/:language', to: "top_voted#language" get '/:category', to: "top_voted#category" the problem with that was the logic could not figure out the difference between the two and caused some conflicts on the back end

OmniAuth doesn't work with Route Globbing in Rails3

為{幸葍}努か 提交于 2019-12-18 11:35:59
问题 I am trying to follow the Railscast 241 Simple OmniAuth and it works fine unless I have Route Globbing at the end of /config/routes.rb : match '*uri' => "posts#index" If I request /auth/twitter with the globbing then OmniAuth does nothing: Started GET "/auth/twitter" for 127.0.0.1 at 2011-04-03 19:17:44 +0200 Processing by PostsController#index as HTML Parameters: {"uri"=>"auth/twitter"} Rendered posts/index.html.haml within layouts/application (9.0ms) Completed 200 OK in 103ms (Views: 14.6ms

In express how do I redirect a user to an external url?

不问归期 提交于 2019-12-18 11:05:13
问题 I have a payment system using node.js and braintree, when the payment is successful I want to send the user to the back end. My back end is setup elsewhere. I have tried res.writeHead(301, {Location: 'http://app.example.io'} ); res.end(); So window.location is obviously not available. I cant think of any ways to redirect a user? 回答1: You can do res.redirect('https://app.example.io'); Express docs: https://expressjs.com/en/api.html#res.redirect 回答2: The selected answer did not work for me. It

In express how do I redirect a user to an external url?

谁都会走 提交于 2019-12-18 11:05:10
问题 I have a payment system using node.js and braintree, when the payment is successful I want to send the user to the back end. My back end is setup elsewhere. I have tried res.writeHead(301, {Location: 'http://app.example.io'} ); res.end(); So window.location is obviously not available. I cant think of any ways to redirect a user? 回答1: You can do res.redirect('https://app.example.io'); Express docs: https://expressjs.com/en/api.html#res.redirect 回答2: The selected answer did not work for me. It

Angular js - show/hide loading gif every new route

我的梦境 提交于 2019-12-18 10:52:48
问题 I'm trying to toggle (hide/show) a loading gif on every new route, so my logic would be: routeChangeStart = show loading gif routeChangeSuccess = hide loading gif This is my code: //ANGULAR app.run(function($rootScope) { $rootScope.layout = {}; $rootScope.layout.loading = false; $rootScope.$on('$routeChangeStart', function() { //show loading gif $rootScope.layout.loading = true; }); $rootScope.$on('$routeChangeSuccess', function() { //hide loading gif $rootScope.layout.loading = false; });