Hi I am new to Python/django and am using VS Code. Now I got python IntelliSense and pylance extension installed and most things are showing up on IntelliSense but some aren't.
How can I get it to work for everything?
I would very much appreciate some insight since it's driving me nuts...
request.POST from an imported lib not showing up
selected_meetup.participants not showing up nor is selected_meetup.participants.add
from urllib import request
from django.forms import SlugField
from django.shortcuts import render
from .models import Meetup
from .forms import RegistrationForm
# from django.http import HttpResponse
# Create your views here.
def index(request):
meetups = Meetup.objects.all()
return render(request, 'meetups/index.html', {
'meetups': meetups
})
def meetup_details(request, meetup_slug):
try:
selected_meetup = Meetup.objects.get(slug=meetup_slug)
if request == 'GET':
registration_form = RegistrationForm()
else:
registration_form = RegistrationForm(request.POST)
registration_form = RegistrationForm(request.)
if registration_form.is_valid():
participant = registration_form.save()
selected_meetup.participants.add(participant)
return render(request, 'meetups/meetup-detail.html', {
'meetup_found': True,
'meetup': selected_meetup,
'form': registration_form
})
except Exception as exc:
return render(request, 'meetups/meetup-detail.html', {'meetup_found': False
})
Update:
That's great guys, I now understand the type problem it's obvious now (only had so many extensions issues especially django/html) I got confused...
Now I added types to Meetup and Participant but selected_meetup.participants. still refused to show me its method ADD.
I assume the problem is the lib is written without types. Is there a way to solve that? because quite valuable to me to be able to see what's possible write away...
have you got solutions to that?
CodePudding user response:
I would re-install the extensions, then make sure it is referencing the right version of python. If that doesn't work I would recommend to just type it out in full and look past the error.
CodePudding user response:
You didn't declare what type of object request is in the programming process. Maybe you can declare request = request () in the code.The second is the same. vscode can't recognize the type of the selected_meetup you wrote. You can hover over these two objects and find that the vscode prompt the type can be any.