为什么我的快速应用程序中的导航栏上没有其他选项卡?(Why won't other tabs on my navbar apear in my express app?)
我正在尝试使用express和charlotte构建一个应用程序。 我正在使用ejs来渲染我的html文件。 我有一个针对css的twitter bootstrap。 出于某种原因:
<div class="navbar navbar-fixed-top"> <div class="navbar-inner"> <div class="container"> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> <a class="brand" href="#"><img src="./img/MySpending.png"></a> <div class="nav-collapse"> <ul class="nav"> <li ><a href="./login.html">Log in/out</a></li> <li class="active"><a href="#">Daily</a></li> <li ><a href="./monthly.html">Monthly</a></li> <li ><a href="./yearly.html">Yearly</a></li> </ul> </div><!--/.nav-collapse --> <div class='navbar_form pull-right'> </div> </div> </div>
对我来说,好像我的html不会在快递中更新。
这是我的app.js快递如果有帮助:
var express = require('express'); var conf = require('./conf'); var everyauth = require('everyauth') , Promise = everyauth.Promise; everyauth.debug = true; var mongoose = require('mongoose') , Schema = mongoose.Schema , ObjectId = mongoose.SchemaTypes.ObjectId; var UserSchema = new Schema({}) , User; var mongooseAuth = require('mongoose-auth'); var path = require('path'); UserSchema.plugin(mongooseAuth, { everymodule: { everyauth: { User: function () { return User; } } } , password: { loginWith: 'email' , extraParams: { phone: String , name: { first: String , last: String } } , everyauth: { getLoginPath: '/login' , postLoginPath: '/login' , loginView: 'login.jade' , getRegisterPath: '/register' , postRegisterPath: '/register' , registerView: 'register.jade' , loginSuccessRedirect: '/' , registerSuccessRedirect: '/' } } , google: { everyauth: { myHostname: 'http://localhost:3000' , appId: conf.google.clientId , appSecret: conf.google.clientSecret , redirectPath: '/' , scope: 'https://www.google.com/m8/feeds' } } }); // Adds login: String mongoose.model('User', UserSchema); mongoose.connect('mongodb://localhost/mydb'); User = mongoose.model('User'); var app = express();/*express.createServer( express.bodyParser() , express.static(__dirname + "/public") , express.cookieParser() , express.session({ secret: 'esoognom'}) , mongooseAuth.middleware() );*/ app.configure( function () { app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); app.engine('html', require('ejs').renderFile); app.use(express.static(path.join(__dirname, 'public'))); }); app.get('/', function (req, res) { res.render('index.html'); }); app.get('/monthly', function (req, res) { res.render('monthly.html'); }); app.get('/yearly', function (req, res) { res.render('yearly.html'); }); /*app.get('/logout', function (req, res) { req.logout(); res.redirect('/'); });*/ mongooseAuth.helpExpress(app); app.listen(3000);
所以我不确定是什么让视图不再更新,因为它目前正在渲染旧版本,导航中只有一个选项卡。 任何有关这方面的帮助将不胜感激。
I'm trying to build an app using express and charlotte. I'm using ejs to render my html files. I have a twitter bootstrap for the css. For some reason this:
<div class="navbar navbar-fixed-top"> <div class="navbar-inner"> <div class="container"> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> <a class="brand" href="#"><img src="./img/MySpending.png"></a> <div class="nav-collapse"> <ul class="nav"> <li ><a href="./login.html">Log in/out</a></li> <li class="active"><a href="#">Daily</a></li> <li ><a href="./monthly.html">Monthly</a></li> <li ><a href="./yearly.html">Yearly</a></li> </ul> </div><!--/.nav-collapse --> <div class='navbar_form pull-right'> </div> </div> </div>
To me it seems like my html won't update in express.
here's my app.js in express if that helps:
var express = require('express'); var conf = require('./conf'); var everyauth = require('everyauth') , Promise = everyauth.Promise; everyauth.debug = true; var mongoose = require('mongoose') , Schema = mongoose.Schema , ObjectId = mongoose.SchemaTypes.ObjectId; var UserSchema = new Schema({}) , User; var mongooseAuth = require('mongoose-auth'); var path = require('path'); UserSchema.plugin(mongooseAuth, { everymodule: { everyauth: { User: function () { return User; } } } , password: { loginWith: 'email' , extraParams: { phone: String , name: { first: String , last: String } } , everyauth: { getLoginPath: '/login' , postLoginPath: '/login' , loginView: 'login.jade' , getRegisterPath: '/register' , postRegisterPath: '/register' , registerView: 'register.jade' , loginSuccessRedirect: '/' , registerSuccessRedirect: '/' } } , google: { everyauth: { myHostname: 'http://localhost:3000' , appId: conf.google.clientId , appSecret: conf.google.clientSecret , redirectPath: '/' , scope: 'https://www.google.com/m8/feeds' } } }); // Adds login: String mongoose.model('User', UserSchema); mongoose.connect('mongodb://localhost/mydb'); User = mongoose.model('User'); var app = express();/*express.createServer( express.bodyParser() , express.static(__dirname + "/public") , express.cookieParser() , express.session({ secret: 'esoognom'}) , mongooseAuth.middleware() );*/ app.configure( function () { app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); app.engine('html', require('ejs').renderFile); app.use(express.static(path.join(__dirname, 'public'))); }); app.get('/', function (req, res) { res.render('index.html'); }); app.get('/monthly', function (req, res) { res.render('monthly.html'); }); app.get('/yearly', function (req, res) { res.render('yearly.html'); }); /*app.get('/logout', function (req, res) { req.logout(); res.redirect('/'); });*/ mongooseAuth.helpExpress(app); app.listen(3000);
So I'm not sure what's keeping the view from updating, because it currently is rendering an older version with only one tab in the nav. Any help with this would be greatly appreciated.
原文:https://stackoverflow.com/questions/17767421
最满意答案
试试这段代码:
import matplotlib.pyplot as pl import numpy as np x = np.linspace(1, 10) def f(x): return np.sin(x) + np.random.normal(scale=0.1, size=len(x)) pl.plot(x, f(x))
它会给你一个带有一些噪音的正弦波:
编辑:
似乎某种随机游走是您正在寻找的。 这个功能会为你做到这一点:
def f(x): y = 0 result = [] for _ in x: result.append(y) y += np.random.normal(scale=1) return np.array(result)
这是它的外观示例(
x = np.linspace(0, 1000, 1000)
):它不再是
x
的函数,因此代码应该被重构以生成带有n
步骤的随机游走。 我会把它留给你:)编辑2:
如果你想要一个更平滑的曲线,你可以应用一个运行平均值( 从这个问题中偷来 ):
def runningMean(x, N): return np.convolve(x, np.ones((N,))/N)[(N-1):] pl.plot(x, runningMean(f(x), 10))
您使用的窗口越大(
N
参数),结果越平滑。例:
Try this code:
import matplotlib.pyplot as pl import numpy as np x = np.linspace(1, 10) def f(x): return np.sin(x) + np.random.normal(scale=0.1, size=len(x)) pl.plot(x, f(x))
It will give you a sin wave with some noise added to it:
Edit:
It seems like some kind of random walk is what you're looking for. This function will do that for you:
def f(x): y = 0 result = [] for _ in x: result.append(y) y += np.random.normal(scale=1) return np.array(result)
This is an example of what it can look like (with
x = np.linspace(0, 1000, 1000)
):It's not a function of
x
any longer though, so the code should probably be refactored to generate a random walk withn
steps instead. I'll leave that to you :)Edit 2:
If you want a smoother curve, you can apply a running mean (stolen from this question):
def runningMean(x, N): return np.convolve(x, np.ones((N,))/N)[(N-1):] pl.plot(x, runningMean(f(x), 10))
The bigger window (the
N
parameter) you use, the smoother the result.Example:
相关问答
更多-
python random的问题[2023-01-13]
for i in range(1,31): x=random.randint(0,600) y=random.randint(0,800) star( x ,y ) -
Random()产生随机数范围[2023-04-06]
你可以把你的许愿望墙分成一个一个可用于显示的小格子。 用随机数来生成,显示在哪个格子内。这样来保证对齐。 每个格子的坐标预先计算好,这样就可以对齐了。又可以达到随机显示位置的目的。 -
在R中使用自定义函数每次产生不同的随机数(Using self-defined functions in R to produce different random numbers Each time)[2022-11-27]
在这个功能: uni_num <- function(k) { Random_Seed <- put_Seed(k) T_value <- T_val(Random_Seed) Random_Seed <- New_Random_Seed(T_value) uniform_num(0, 1, Random(Random_Seed)) } 赋值Random_Seed <-的目标 ... -
线程产生相同的随机数?(Threads produce same random number?)[2022-04-29]
您不应该将rand用于与线程相关的伪随机生成。 该函数使用所有线程共有的共享状态。 这创建了由线程绘制的PRN之间的依赖关系,并且由于对状态的访问必须被互斥,所以大幅减慢。 POSIX系统上的替代品是nrand48和jrand48 ,它们接收一个状态(应该是线程特定的)作为它们的参数。 正如其他人所说的那样,仅仅用时间价值来培育这种状态并不是一个好主意,线程可能会在同一时间做到这一点。 You shouldn't use rand for pseudo random generation in connec ... -
产生随机波函数(Produce random wavefunction)[2024-01-04]
试试这段代码: import matplotlib.pyplot as pl import numpy as np x = np.linspace(1, 10) def f(x): return np.sin(x) + np.random.normal(scale=0.1, size=len(x)) pl.plot(x, f(x)) 它会给你一个带有一些噪音的正弦波: 编辑: 似乎某种随机游走是您正在寻找的。 这个功能会为你做到这一点: def f(x): y = 0 res ... -
随机函数的差异(Differences in random functions)[2021-10-19]
int random = (int)(Math.random()*(x); 这设置random等于0和x - 1之间的任何整数。 int random = 1 + (int)(Math.random()*(x); 将整体表达式加1只是将其更改为1和x之间的任何整数。 (int)(Math.random()*((100-1)+1)) 是多余的,相当于 (int)(Math.random()*(100) 所以请注意: 1 + (int)(Math.random()*(x)返回1到x + 1的int 但 ... -
random()* random()分布如何?(How does random() * random() distribution look like? [duplicate])[2022-09-22]
# test.py import numpy as np import matplotlib.pyplot as plt N = 10**6 plt.hist(np.random.uniform(size=N) * np.random.uniform(size=N), bins=50, normed=True) plt.show() 运行python test.py会产生: # test.py import numpy as np import matplotlib.pyplot as plt N = ... -
随机函数在方案中(random function in scheme)[2022-02-21]
(define (random-element list) (list-ref list (random (length list)))) (define (random-element list) (list-ref list (random (length list)))) -
是的,你可以,你可以实现自己的LCG号码生成器,但正如Sarnold所提到的,你需要在两次通话之间保持状态。 Yes you can, you can implement your own LCG number generator, but as Sarnold mentions you need to maintain state between calls.
-
随机函数(Random Functions)[2021-12-19]
y = new Random(); x = y.Range(0, 1); if (x == 0) { generateExample(); } else if (x == 1) { generateExample2(); } y = new Random(); x = y.Range(0, 1); if (x == 0) { generateExample(); } else if (x == 1) { generateExample2(); }