Is there a proper way to write a path url in django? - django-urls

I'm using django 2.2 to make a blog project, following an old tutorial (that uses django-1.1) the code goes like this:
...
url(r'^post/new/$', views.CreatePostView.as_view(), name='post_new')
...
now in my trial to write the urlpatterns using path instead of url and regular expressions, i translated the code to be:
...
path('post/new/', views.CreatePostView.as_view(), name='post_new')
...
and every time i try to run the server it throws the following error at me:
Exception Type: ValueError at /post/new/
Exception Value: invalid literal for int() with base 10: 'new'
but accidentally i rewrote the url to be as:
...
path('post_new/', views.CreatePostView.as_view(), name='post_new')
...
and it worked fine for me!
so is there a specific way that more recent versions of django accept, which i should stick to in order to name my paths the right way?
also, what does the error mean?

Related

Here Maps Routing Api returning 404 1 out of 5 times

I've integrated Here maps JS into a website, and when I call the "calculateRoute" method like so: router.calculateRoute(routingParameters, onRoutingResult), this makes a call to the following URL which returns a 404 most of the time.
https://route.ls.hereapi.com/routing/7.2/calculateroute.json?xnlp=CL_JSMv3.1.9.0&apikey=my-api-key&mode=fastest%3Bcar&waypoint0=geo!-33.873367%2C151.247373&waypoint1=geo!-33.873392%2C151.224161&routeAttributes=sh
When it works, it returns the JSON structure as expected
Is this a temporary issue? Or am I doing something wrong?
for all having problems with the examples from the "quick start" doc, check your URL against these:
https://developer.here.com/documentation/examples/rest/routing

How can I add 'path' to my Artifactory AQL query?

I'm using insomnia to make calls to the Artifactory API.
I have the following query, which works really well:
items.find({"repo":{"$eq":"my-repository-virt"}}, {"$and":[{"#my.fileType":{"$match": "jar"}},{"#my.otherType":{"$match": "type2"}},{"#prodVersion":{"$match": "false"}}]})
But I have a problem in that there are duplicate files in some sub-folders with the same properties/filename that I would like to exclude.
I would like to add path to this query, but I can never get any results returned.
The repository is a virtual repository that links to 3 other real repositories.
One of my colleagues can call the following query with the command line tool and get the expected results:
jfrog rt search my-repo-snapshots/myproject/subfolder/jars/*.jar
I have tried adding the path parameter to my query, I've tried removing everything except the repo and the path, like this:
items.find({"repo":{"$eq":"my-repo-snapshots"}},{"path" : "my-repo-snapshots/myproject/subfolder/jars/*.jar"})
I've tried with just the path, with variations on the path, including/excluding the repo name, using the virtual repo, the actual repo, but I always get a successful search with 0 results returned.
How can I build this query to search the virtual repo, along a certain path, and including certain properties?
EDIT:
I've also tried:
items.find({"repo":{"$eq":"my-repo-snapshots"}},{"path" : {"$match":"my-repo-snapshots/myproject/subfolder/jars/*.jar"}})
Both with the repo in the path and without, I still get 0 results.
OK I figured it out.
The path part needs to be added in with the {"$and": ...} section where the properties are included. Like so:
items.find({"repo":{"$eq":"my-repository-virt"}},
{"$and":[
{"path":{"$match":"path/to/relevant/folders/*"}},
{"#my.fileType":{"$match": "jar"}},
{"#my.otherType":{"$match": "type2"}},
{"#prodVersion":{"$match": "false"}}
]})
The easier fix would have been:
items.find({"repo":{"$eq":"my-repo-snapshots"}},{"path" : {"$eq":"my-repo-snapshots/myproject/subfolder/jars"}, {"name" : {"$match":"*.jar"}})
So the problem with your initial attempt, is that the "path" should match the folder and the "name" should match the filename

Meteor Iron Router does not get Current Path from Route

In a Template Helper I get the current path from Iron.Router (iron:router) as follows:
Router.current().route.path(this);
This works fine, unless the route path does contain parameters (e.g. /client/:_id/edit). In that case the path() function returns null.
How do I get the current path within a Template Helper, when the route contains parameters?
There are posts around covering the issue but the solution mentioned there seem not to fit.
I'm using Meteor 1.1.5 with iron:router1.0.7
According to this iron-router/issues/289 there are problems when the path contains parameters. The suggestion to use Iron.Location.get().path This works well for me.

Meteor's Iron.Router adding an extra "/" to route names and not allowing home route

I am having a problem getting iron-router to correctly store and access routes. It appears that Iron.Router is adding an extra slash (/) before the route names, not ignoring case for template names, and not creating a default route.
I am adding Iron.Router to a simple testing app I have that I have split up for separate pages, but I cannot get any page to work as documented either with the map() or route() functions. I have spent hours trying options and searching and I seem to be the only one who ever had this problem. So I set up a minimum project to test. I created a new meteor project, removed the files, then copied basic.js and basic.html from https://github.com/EventedMind/iron-router/tree/devel/examples. All this example does is show three pages when you click between them. I then…
vagrant#precise32:/vagrant/test$ meteor add iron:router
vagrant#precise32:/vagrant/test$ meteor update
This project is already at Meteor 0.9.3.1, the latest release.
Your packages are at their latest compatible versions.
vagrant#precise32:/vagrant/test$ npm version
{ http_parser: '1.0',
node: '0.10.32',
v8: '3.14.5.9',
ares: '1.9.0-DEV',
uv: '0.10.28',
zlib: '1.2.3',
modules: '11',
openssl: '1.0.1i',
npm: '2.1.2' }
vagrant#precise32:/vagrant/test$ ls
basic.html basic.js.
vagrant#precise32:/vagrant/test$ meteor
It started successfully, but threw a JS error on in Chrome (or FF). Exception from Tracker recompute function: Error: Couldn't find a template named "/" or "". Are you sure you defined it? Well yes, I did. Giving the route a blank name generates no error and no home page. So next I tried adding “/one” on the URL. I then get the JS error Error: Oh no! No route found for path: "/one". Next I changed the parameter in my route() call from “/one” to “one” and got this error: Error: Couldn't find a template named “one” or “one”. Are you sure you defined it? I then tried adding explicit code for route “one”: “function() { this.render(“Home”)} to reference the template “Home” using the same case. I got the exact same error message as without the explicit code. The only way I could get page one to display was to changed the name from “One” to “one” in the HTML. I couldn't get the default page to display at all.
When poking around (using Chrome’s console) in some internal variables, I found Router.routes, which has this highly suspicious content:
>Router.routes.forEach( function(v) {console.info("name = '%s', originalPath = '%s', re = '%s'",v.name,v.originalPath,v.re)})
2014-10-04 16:10:07.756 name = '/', originalPath = '//', re = '/^//?$/i'
2014-10-04 16:10:07.757 name = '/one', originalPath = '//one', re = '/^//one/?$/i'
2014-10-04 16:10:07.758 name = '/two', originalPath = '//two', re = '/^//two/?$/i'
(If I name the path "one", then the route will show 'one' as the name, and '/one' as the originalPath.
Details: This is a brand new folder with only these two files in it (and the hidden .meteor folder). The only package added was “iron:router”. I did a meteor update just before my last round of testing (one hour ago). I have set no environment variables. I have the latest version of Chrome & FireFox. I am using VirtualBox via Vagrant from Window 8 with 12G memory. Every other Meteor project I’ve done so far works, (well except for some trying to use jQuery).
If this was a bug in Iron:router, someone else would have noticed, but there are no more settings I can find anywhere that could be adding or subtracting the extra “/” in Iron-Router. Anyone have any ideas of what I need to look for for making a vanilla Iron-Router work with a vanilla Meteor project on my machine?
You are really out of luck because your problem is very simple : you are running examples which are intended to work with the LATEST iron:router#1.0.0-pre3, but your iron:router version is most likely 0.9.4.
Try this :
meteor remove iron:router
meteor add iron:router#1.0.0-pre3
If you want a little more insight, routes used to be declared with name first and path as an option, this is now the contrary.
0.9.4
Router.map(function(){
this.route("home",{
path:"/"
});
});
1.0.0-pre3
Router.route("/",{
name:"home"
});

Playframework 2 SQLite

I am trying to get SQLite working with the playframework but so far no luck.
I have Downloaded sqlitejdbc-v056.jar and put it into the lib folder.
I then changed the application.conf:
db.driver=org.sqlite.JDBC
db.url="jdbc:sqlite:/db/geolookup.sqlite"
db.default.user=sa
db.default.password=sa
I created a folder db and drop my sqlite db into it.
Now I start play with play run
Everything seems to compile ok, but when I call the url: http://127.0.0.1:9000
I get the following error:
driver.url has type STRING rather than OBJECT
with the following line highlited:
db.driver=org.sqlite.JDBC
What am I missing?
try this:
db.default.driver="org.sqlite.JDBC"
db.default.url="jdbc:sqlite:/home/tex/dbtest"
db.default.user="sa"
db.default.password=""
Notice that the folder of the db must be an absolute path !
(BTW: with this configuration the application starts but when I try to run the evolution it throws an exception, I think this is a "dialect" problem...)
Hope this helps...
You are propably using the wrong method to get the data from the config. From your error I assume you use it like this:
configuration.getConfig("db.driver")
But this method expects an JSON object under the path "db.driver". Since under the "db.driver" path you have a string, you should read the data using this method:
configuration.getString("db.driver")
This will make the "rather than OBJECT" error go away.

Resources