#get user logged info and display in profile page
43 messages · Page 1 of 1 (latest)
I am getting error fetching the profile: The string did not match the expected pattern
You should copy paste the entire error and traceback. See #readme-1st for how to format code and errors.
What line is causing this? SyntaxError: The string did not match the expected pattern.
I’m not sure because everything runs fine but In my console it says that. I don’t think I can send an image but I’ll try copy and paste my console more
In that error it will link you to the code.
Ah ok I see I think
One sec
import UserProfile from './components/UserProfile.vue';
export default {
components: {
UserProfile,
},
data() {
return {
authenticated: false,
user: null,
};
},
mounted() {
this.fetchUserProfile();
},
methods: {
async fetchUserProfile() {
try {
const response = await fetch('/api/get_user_profile/');
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
this.user = data;
this.authenticated = true;
} catch (error) {
console.error('Error fetching user profile:', error);
}
},
},
};
</script>```
This part more specifically
mounted() {
this.fetchUserProfile();
},
Which part of that function?
Is there a way for me to send an image in this thread
What is it an image of?
The console
Copy and paste?
I’m not sure which part
Ty I will read into this
My log shows that error just after this export default { components: { UserProfile, }, data() { return { authenticated: false, user: null, }; }, mounted() { this.fetchUserProfile(); },
Check the response from the server in your network panel. It's not JSON
async fetchUserProfile() {
try {
const response = await fetch('/api/get_user_profile/');
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
this.user = data;
this.authenticated = true;
} catch (error) {
console.error('Error fetching user profile:', error);
}
},
},
};```
The line error fetching user profile : ‘, error is what I’m being linked to in the console
Though that’s just a a debug statement
My App.vue has a 304 not modified as the status in the network tab
Welp a 304 is a redirect http response and won't have a body which means it wouldn't be convertable to JSON. That explains your error
Any idea how I could fix this it if there is an alternative method
Why is /api/get_user_profile/ returning a 304?
That , UserProfile.vue , App.vue , bootstrap.min.css, main.js, client all have the 304 not modified
I’m not sure at all because in my backend when I run that in my :8000 local that path runs fine
And it displays they user information
It’s when I try to take that data and display it in my vue that I get a problem
Oh. We're talking about different things. When your code runs await fetch('/api/get_user_profile/'), what is that corresponding request in your network panel of the developer tools?
In my network panel where exactly am I looking
Am I looking for a name
That has get_user_profile
I don’t see that
I have the columns name , domain , type , initiator , transfer size and time
I’m not sure where I’m looking
Are you familiar with how that panel works?
I’m not sure to be honest but I’ve been debugging and added some more debug statements and you are correct api/get_user_profile is returning a html page instead of JSON data
It might be worth researching a bit: https://www.youtube.com/watch?v=lhNIXaIv5vc
https://developer.chrome.com/docs/devtools/network
After an overview about the basics of the Chrome Developer Tools, in this video I go through more advanced uses of the Network Tab. Learn how to create screenshots of a loading page, check domain origin and HTTP responses, format responses, customize the panel and test loading performance with different internet connection speeds, and much more!...
A tutorial on the most popular network-related features in Chrome DevTools.