I'm trying to learn django but the instructor uses django 1.X.X.
So far, I've been able to update stuff to Django 3.X.X to get it working.
But I'm stuck now.
Specifically, in the below urlpatterns code:
urlpatterns = [
path('',views.SchoolListView.as_view(),name='list'),
path('<int:pk>/',views.SchoolDetailView.as_view(),name='detail')
]
The first path works. The second one doesn't.
When I click on the url nothing happens. No error code, nothing.
I think there is a problem with the syntax? Is it different for Django3?
I checked the documentation and couldn't find anything wrong.
Thank you.
For example:
path ('',views.index , name='index')
For your code:
path('',views.SchoolListView,name='list')
The second pattern is part of djangos generic view .Generic views abstract common patterns to the point where you don’t even need to write Python code to write an app.
path('<int:pk>/',views.SchoolDetailView.as_view(),name='detail')
Here pk represents primary key. Check if you have data with primary key you are giving in database.
Alternatively if u dont want to use generic method, you can use this
path('<int:school_id>/‘, views. SchoolListView, name='schoollist')
, where school_id(it can be other name depending on your model, verify it in db) should be the primary key in database created by django.
Related
I use jooq to generate objects against a local database, but when running "for real" later in production the actual databases will have different names. To remedy this I use the <outputSchemaToDefault>true</outputSchemaToDefault> config option (maven).
At the same time, we have multiple databases (schemas), and are using a connection pool to the server like "jdbc:mysql://localhost:3306/" (without specifying a database here).
How do I tell jooq which database to use when running queries?
I have tried all config I can think of:
new Settings()
.withRenderSchema(true) // true/false seems to make no difference.
.withRenderCatalog(true) // true/false seems to make no difference.
.withRenderMapping(new RenderMapping()
.withDefaultSchema("my_database") // Seems to have no effect.
// The above 3 configs always give me an error saying "no database selected".
// Adding this gives me 'my_database.my_table' does not exist - while it actually does.
.withSchemata(new MappedSchema()
.withInputExpression(Pattern.compile(".*"))
.withOutput("my_database")
));
I have also tried using a database/schema name, as in not configuring outputSchemaToDefault. But then, adding the MappedSchema code above, but that gives me errors with "'my_databasemy_database.my_table' does not exist", which is correct. I have no clue why that code gives me the database/schema name twice?
Edit:
When jooq tells me that the db.table does not exist, if I put a break point in a good place and get the sql from jooq and run exactly that against my database it does work. But jooq fails to run it.
Also, I'm using version 3.15.3 of jooq.
I solved it. Instead of using .withInputExpression(Pattern.compile(".*")), it seems to work with .withInput("").
I'm still not sure why it works, or if this is the "correct" way of solving it. But at least it is a way forward.
No clue why using the pattern, I got the name twice though. But that one I'll leave alone.
I'm trying to connect my NestJs Project with a Oracle db and I'm using TypeORM and the status of connection is ok but I don't know how I can connect with a function. This function is into of a package and at the same time this package is into of a schema. The structure is like:
mySchema:
--------->myPackage:
-------------------->myFunction(id)
In the NestJS code I'm define this import in the AppModule file:
When I try to use the entity I don't know what method can I use to connect with my function. With the ESLint I get the next methods:
I hope to be clear and thanks for all!
In you last picture you’re trying to make a request to the database and as you can see, when you mentioned the testRepository and dots(.) now you have to tell him what you want to do in your database and in the suggested list you have all the possible possibilities.
So if you want to get or fetch data from you database, you will use testRepository.find() this will give you everything in that particular entity. To do that, you have to do something like below, before that you code has something that I have never seen in Nest, (public); if it does exist but I won’t use that in my Example since I don’t know it in Nest and also; you have started writing without (return) I don’t know how you’re expecting to return what you will get from your database.
Here is my example:
in your controller:
#Get() AnyThing(): Promise<TestEntity[]> {return this.DaobscsService.whatEver(); }
And in your service:
#InjectRepository(TestEntity) private readonlytestRepository: Repository<TestEntity>, ) {}
async whatEver(): Promise<TestEntity[]> {return await this.testRepository.find();}
What ever name you gonna use instead (whatEver()) in the service that have used, remember to use the same name in your controller pointing to service (this.Boa...Service.(The name here) OOP system’s you know it I hope
This example is to get or fetch so if you don’t have any thing in your database then you will get nothing! if that’s not what u want then command with a full version of what exactly is your issue, what u expected and code from controller, service, and module.
I'm able to generate query for multi inserts or update thanks to pg-promise helpers but I was wondering if I could follow the advice of the author and put all queries outside of my javascript code (See here https://github.com/vitaly-t/pg-promise/wiki/SQL-Files and here : https://github.com/vitaly-t/pg-promise-demo).
When I use the insert helpers, the return query looks like :
INSERT INTO "education"("candidate_id","title","content","degree","school_name","start_date","still_in","end_date","picture_url") VALUES('6','My degree','Business bachelor','Bachelor +','USC','2018-05-15T02:00:00.000+02:00'::date,false,null::date,null),('6','Another degree','Engineering','Master degree','City University','2018-05-15T02:00:00.000+02:00'::date,false,null::date,null)
The idea is that I don't know how many inserts I want to do at the same time, so it has to be dynamic.
The following code doesn't work as I'm passing an array of object instead of an object :
db.none(`INSERT INTO "education"("candidate_id","title","content","degree","school_name","start_date","still_in","end_date","picture_url")
VALUES($<candidate_id>, $<title>, $<content>, $<degree>, $<school_name>, $<start_date>, $<still_in>, $<end_date>, $<picture_url>)`, data)
This code spreads the object but is still not correct to make a proper query :
db.none(`INSERT INTO "education"("candidate_id","title","content","degree","school_name","start_date","still_in","end_date","picture_url")
VALUES($1:list)`,
[data])
Any idea ? Is it at least possible or in the case where I don't know how many records I want to insert in advance I have to call pgp.helpers everytime ?
You confuse static and dynamic SQL. SQL files are there for SQL queries that are mainly static, i.e. you still can inject dynamically a lot, but when most of the query is dynamic, there is no longer any point putting it into an SQL file.
And the helpers namespace is there for dynamic queries only. So you are asking about two separate things, to join things that do not need to be joined.
I'm new with node and compound. While i tried to scaffold
compound g crud leaveApplication leave_code:string description:string applicable:string carry_forward:boolean limit_type:boolean lop:boolean od:boolean co:boolean leave_revision:boolean active:boolean
I was getting some errors, then i tried
compound g crud leave code:string description:string applicable:string cForward:boolean limit:boolean lop:boolean od:boolean co:boolean leave_revision:boolean active:boolean
But the error now occurred was in the name of routes
leaves GET /leaves.:format? leaves#index
leaves POST /leaves.:format? leaves#create
new_leafe GET /leaves/new.:format? leaves#new
edit_leafe GET /leaves/:id/edit.:format? leaves#edit
leafe DELETE /leaves/:id.:format? leaves#destroy
leafe PUT /leaves/:id.:format? leaves#update
leafe GET /leaves/:id.:format? leaves#show
These were the routes i was getting.
Why is that so?
it looks like compound is turning your model name into plural (=leaves) and then, instead of using your provided singular name, turning this plural name back, resulting in "leaf".
Does this make any sense? ;-) Or did I get you question wrong?
If you could provide the "some errors" and the full error message, it would be easier to help ;)
Btw, I just experienced that using camel case for models doesn't seem to be a good idea with compound.js.
It's mangeling the camelcase in some places (e.g. inside the controllers), but in others not (schema.js) creating a application with some errors...
Is there any form to create subdirectories dynamically in playframework?, I was thinking in a common interceptor like spring, but.. how can I do it in play??
Thanks for any help
example.com/event1
example.com/event2
example.com/event3
Best way, I think, is to use the routes file. Documentation here should be self-explanatory:
http://www.playframework.org/documentation/1.2.2/routes
(see e.g. http://www.playframework.org/documentation/1.2.2/routes#syntax)
You can use the routes file, but be aware that the "name" of the folder must be a key that allows you to find the object. Usually the "key" will related to an entity, and in that case Play provides a Long id as key which is a better choice. After that key you can add some string for SEO-usability purposes.
So your routes would be something like:
example.com/1/event1
example.com/2/event2
example.com/3/event3
(or alternatively)
example.com/event/1
example.com/event/2
example.com/event/3
using a routes file like:
GET /{id}/{name} MyController.getFolder
or
GET /event/{id} MyController.getFolder
There are some questions around here (SO) on how to add the extra text to the path.