APY
Can anyone help me out? I have this question I need to implement autocomplete function in my search box of html page in django And i need to use source as a URL which contains Json data. What could be the code for it? Right now i wrote this and it wont work… <script> $ (Function ()) $( "#name" ) .autocomplete ({ source: “localhost:8983/solr/test/select?indent=on&g=*:*&wt=json” minLength: 2 ]): </script>
cj
Print stuff in console
that's not how to test things
cj
Hi 👋🏻 I need you helps How can I test if my Django background task works or not ?
write the proper test cases and use pytest or django's UnitTest, of course
Raj
Can anyone one help me in starting django project i am facing lots of problems
() { :;}; echo Nickolas
Raj
There are enough tutorials, read one.
No that didn't solved my problem
() { :;}; echo Nickolas
() { :;}; echo Nickolas
How do you expect people to help you if you say hello i have problems. Smh
Raj
Do you want to help me? If so I will be so glad 🥰
Doragonsureiyā
Can anyone one help me in starting django project i am facing lots of problems
Don't ask meta questions like: "Any user of $x here?" "Anyone used technology $y?" "Hello, I need help on $z!" Just ask directly! The better you are at explaining the problem, the more likely you are to get help. Asking smart questions
Eliphaz
Hey guys please do you know a method to implement like system with Django and JavaScript on a blog article ? I created a like model with article_id , user_id and liked to default True
Eliphaz
When I add a like with JavaScript ajax I don't receive the current count value of the like in database I received old state
Eliphaz
Sorry I'm going to share a portion of my code
Eliphaz
class Like(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) article = models.ForeignKey(Article, on_delete=models.CASCADE) liked = models.BooleanField(default=True)
Eliphaz
it's the Like model
Eliphaz
my like_request method : https://pastebin.com/aBX4LNKF
Eliphaz
sorry I'm a beginner with Django I'm learning
() { :;}; echo Nickolas
sorry I'm a beginner with Django I'm learning
Nowhere in the shared code do you increment the value, hence you receive the old value
Eliphaz
Nowhere in the shared code do you increment the value, hence you receive the old value
hummm nope but in the pastebin code you can see I 've do some repeat of code by make a request every time a like state change to the database to check the last count
Eliphaz
Nowhere in the shared code do you increment the value, hence you receive the old value
It work but I know i'ts a bad idea to do this :/ you think I should increment the value in the template directly with javascript ?
Eliphaz
my like_request method : https://pastebin.com/aBX4LNKF
in my urlpatterns on app/urls.py: path('<slug:slug>', ArticleView.as_view(), name="article_detail"), #<= here the path of a article path('ajax/like', like_request, name="article_detail_like"), #<= here the path of the ajax request
Sumit
HI, HOw to open aws s3 file from django-admin
Sumit
Used django-storages package
Sumit
opening file is giving xml output ` <Code>PermanentRedirect</Code> <Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message> `
() { :;}; echo Nickolas
Your URL/ajax code is irrelevant, explain the use case
Eliphaz
I don't know what you want to do ..
I want to get the like count in my template of article detail and update that from JavaScript with ajax
Eliphaz
Your URL/ajax code is irrelevant, explain the use case
Yeah I know the first path is for display my article detail view , the second I path is for make the like request to add new like and update like state from liked to no liked
() { :;}; echo Nickolas
I want to get the like count in my template of article detail and update that from JavaScript with ajax
Why do you have custom request methods and are you not just using a modelviewset?
() { :;}; echo Nickolas
Modelviewset gives you crud by default without writing any code
Eliphaz
Why do you have custom request methods and are you not just using a modelviewset?
I thought that is a better way to do it because I return a Json response
Eliphaz
Modelviewset gives you crud by default without writing any code
Oh yeah 🤩 so use it in the same url path ? But with LikeView ?
() { :;}; echo Nickolas
I thought that is a better way to do it because I return a Json response
Viewsets return json by defualt unless you override the parser
() { :;}; echo Nickolas
It sounds to me like you're trying to build a backend and a JS based front end, look into django rest framework and it's viewsets
Eliphaz
Viewsets return json by defualt unless you override the parser
Viewsets is in Django Rest Framwork I use Django Framework :/
() { :;}; echo Nickolas
Django rest framework is django, it just separates your back end from the front end
() { :;}; echo Nickolas
or in other words, django rest framework is django without the views/templates. Instead, endpoints return a JSON object unless specified otherwise.
() { :;}; echo Nickolas
DRF also comes with a browsable interface, you can use it to create/edit/delete/et. al. objects
() { :;}; echo Nickolas
All without writing any (very little) code. It's all the same, you define a model, create a serializer, define a viewset that has like 0 business logic to have CRUD OOTB and you're good to go
() { :;}; echo Nickolas
It's only when you'll want to integrate more complex stuff or build a proper application that you'll need to override the view methods or serializer methods.
() { :;}; echo Nickolas
You can use JS in templates. Just define a script block and off you go
Mr
hello django users. Can I create web aplication that broadcasting tv channels?
() { :;}; echo Nickolas
It's what I have do
You don't "have to do" anything. You need to evaluate your use case write out a design and decide on how you want to build out the app
Eliphaz
You don't "have to do" anything. You need to evaluate your use case write out a design and decide on how you want to build out the app
I'm learning Django Framework this small project it's my first project after the django framework documentation tutorial Polls app
Eliphaz
I'm learning Django Framework this small project it's my first project after the django framework documentation tutorial Polls app
I've don't write the use case for this app just think about simple crud app ( here a blog ) and now I just want to add a like button with ajax
() { :;}; echo Nickolas
Well, same remarks then. You have a POST endpoint that is supposed to increment the amount of likes on a blog post but no where in your business logic do you increment the like counter.
() { :;}; echo Nickolas
Furthermore, why is like a boolean, likes are integers
Eliphaz
Furthermore, why is like a boolean, likes are integers
the like is not a boolean, I've created a like model who take the user_id the article_id and liked (it's for see if a user have already liked a article)
() { :;}; echo Nickolas
the liked is a boolean
What do you need that for
Эндейл
Hey guys, how can i create simple quiz app in django, plz help me.
() { :;}; echo Nickolas
A blog has posts, a post has an author, likes, exc..
Eliphaz
A blog has posts, a post has an author, likes, exc..
so I don't need to create a separate like model ?
Eliphaz
I've create the like model for separate like with article model
Raj
PS C:\Users\rajla> python manage.py runserver C:\Program Files\Python310\python.exe: can't open file 'C:\\Users\\rajla\\manage.py': [Errno 2] No such file or directory
Raj
do any one has answer
Maxim
do any one has answer
where is the question?
() { :;}; echo Nickolas
do any one has answer
Dude... Navigate in the project
G4st0n
exactly, move to manage.py location
G4st0n
also if using virtualenv can use pip shell and django-admin commands
omurzhanov
Hii, I’m creating a Django website and there will be petitions app, posts app. As you already guessed, I have petitions and post models. And you can comment on petitions as well as posts. How can I implement comment model? Do I have to implement comment model to each one, like PetitionComment, PostComment ? Or how can I implement? Thank you
Philemon
Anybody who knows of Django freelance site?
Lord
'''ValueError: not enough values to unpack (expected 2, got 1)''' am trying to run my and this occurs I need help please
Lord
the bot is not allowing it
Navroz
Navroz
'''ValueError: not enough values to unpack (expected 2, got 1)''' am trying to run my and this occurs I need help please
You are asked to send two values but now you are sending one value. {% url "...." smth.id smb.id %} You must write like this, I think
Lord
actually I have'nt written any views.py and urls.py am just trying to my admin page
Lord
actually I have'nt written any views.py and urls.py am just trying to my admin page
actually I have'nt written any views.py and urls.py am just trying to test my admin page
Navroz
actually I have'nt written any views.py and urls.py am just trying to test my admin page
Ok. Sorry, I think I don't understand, I am a new pythoner😅
Lord
alright
Doragonsureiyā
the bot is not allowing it
To share code or error tracebacks, use a pasting service, like: - https://linkode.org - https://dpaste.org
Deep
Hi folks, django celery with redis is executing same task thousand of times. What could be issue?