Skip to content

Instantly share code, notes, and snippets.

@paltman
Last active April 20, 2020 15:46
Show Gist options
  • Save paltman/7225dbf00202e332bf8f98c4887bf747 to your computer and use it in GitHub Desktop.
Save paltman/7225dbf00202e332bf8f98c4887bf747 to your computer and use it in GitHub Desktop.
Example Vue/Django App
def bookmarks(request):
data = [b.data() for b in Bookmark.objects.all()]
return JSONResponse(data=dict(bookmarks=data))
<template>
<div class="bookmark-list">
<button @click="refresh">Refresh</button>
<div v-for="(bookmark, index) in bookmarks" :key="index">
<a :href="bookmark.url">{{ bookmark.title }}</a>
</div>
</div>
</template>
<script>
import api from './api';
export {
data() {
return {
bookmarks: [],
}
},
methods: {
refresh() {
api.getBookmarks(data => {
this.bookmarks = data.bookmarks;
});
}
},
created() {
this.refresh();
}
}
</script>
class Bookmark(models.Model):
title = models.CharField(max_length=250)
url = models.CharField(max_length=500)
def data(self):
return dict(title=self.title, url=self.url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment