Your SlideShare is downloading. ×
The django quiz
The django quiz
The django quiz
The django quiz
The django quiz
The django quiz
The django quiz
The django quiz
The django quiz
The django quiz
The django quiz
The django quiz
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
668
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. ### Easy1.You have a class defined as class Post(models.Model): name = models.CharField(max_length=100) is_active = models.BooleanField(default=False)You create multiple objects of this type. If you doPost.objects.get(is_active=false),what exceptions is raised?a. MultipleObjectsReturnedb. ManyObjectsReturnedc. SyntaxErrord. MultipleModelReturnede. ManyModelReturned2. Where is the function render_to_response defined?a. django.viewsb. django.shortcutsc. django.templatesd. django.contrib.templatese. django.contrib.shortcuts3. What is the default name for the table created for model named Postin application bloga. post_blog Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com
  • 2. b. blog_postc. postblogd. blogposte. Postblog4. How do you send a 302 redirect using django?a. return HttpRedirectResponse()b. return HttpResponseRedirect()c. return HttpRedirectResponse(permanent=True)d. return HttpResponseRedirect(permanent=True)e. return HttpRedirectResponse5. In django.contrib.auth, Users passwords are kept in what form?a. Plain textb. Hashedc. Encryptedd. Hashed then encrypted3. Encrypted then hashed6. Which of the following is correct way to find out if a request usesHTTP POST method?a. request.is_post() == Trueb. request.METHOD == postc. request.METHOD == POSTd. request.method == poste. request.method == POST7. Generic views have access to request context.a. Trueb. Falsec. Default is True but can be set to False by GENERIC_REQUEST_CONTEXT in settings. Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com
  • 3. d. Default is False but can be set to True by GENERIC_REQUEST_CONTEXT in settings.e. Can not be determined without extra information.8. The current released version of Django isa. 0.96b. 1.0c. 1.1d. 1.2e.Vyper logix 2.09. Which of these is a correct context_processor?a.def featured_posts(request): return Post.objects.filter(is_featured=True)b.def featured_posts(request): return {featured_posts: Post.objects.filter(is_featured=True)}c.def featured_posts(request, response): return Post.objects.filter(is_featured=True)d.def featured_posts(request, response): return {featured_posts: Post.objects.filter(is_featured=True)}e. Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com
  • 4. def featured_posts(request, response): response.write(featured_posts= Post.objects.filter(is_featured=True))10. Which of the following is a valid Middleware?a.class LatestPostMiddleware: def process_request(request): request.latest_post = Post.objects.latest()b.class LatestPostMiddleware(django.middlewares.BaseMiddleWare): def process_request(request): request.latest_post = Post.objects.latest()c.class LatestPostMiddleware(django.middlewares.BaseMiddleWare): def process_request(request): return {latest_post: Post.objects.latest()}d.class LatestPostMiddleware(): def process_request(request): return {latest_post: Post.objects.latest()}e.class LatestPostMiddleware(): def process_request(request): request.write(latest_post= Post.objects.latest()) Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com
  • 5. #Moderate11. In the model below which line can be removed for the class to workclass Post(models.Model): name = models.CharField(max_length = 100)#Line 1 desc = models.TextField()#Line 2 post = models.ForeignKey(Blog)#Line 3 blog = models.ForeignKey(Blog)#Line 4a. Line 1b. Line 2c. Line 3d. Line 4e. Either of line 3 or 412. Who can access the admin site in Django?a. user with is_super_user Trueb. user with is_staff Truec. user with is_admin Trued. Either of a or be. Either of a, b, c13. Which of the following code is closest to login_required decorator in Django?a.def login_required2(request): if request.user.is_authenticated(): return True else: Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com
  • 6. return False b. def login_required2(request, view_func): def check_login(request): if request.is_authenticated() and request.has_permissions(request.REQUIRED_PERMISSIONS): return view_function(request) else: return HttpResponseRedirect(/login/) return check_login(view_func) c. def login_required2(request, view_func): def check_login(request): if request.is_authenticated(): return view_function(request) else: return HttpResponseRedirect(/login/) return check_login(view_func) d. def login_required2(view_func): def new_func(request): if request.user.is_authenticated(): return view_func(request) else: return HttpResponseRedirect(/login/) return new_func Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com
  • 7. e. def login_required2(view_func): def new_func(request): if request.user.is_authenticated() and request.has_permissions(request.REQUIRED_PERMISSIONS): return view_func(request) else: return HttpResponseRedirect(/login/) return new_func 14. Which of the following is a valid method to model Many to many relation ship in Django? a. class Foo(models.Model): bar = models.ManyToManyField(Bar) class Bar(models.Model): foo = models.ManyToManyField(Foo) b. class Foo(models.Model): bar = models.ForeignKey(Bar) class Bar(models.Model): foo = models.ForeignKey(Foo) c. class Foo(models.Model): bar = models.ManyToManyField(Bar) Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com
  • 8. class Bar(models.Model): pass d. both B and C e. All a, b, c 15. Which of the following is not included by default inTEMPLATE_CONTEXT_PROCESSORS a. django.core.context_processors.auth b. django.core.context_processors.debug c. django.core.context_processors.i18n d. django.core.context_processors.media e. django.core.context_processors.request 16. Which of these is the currect way to validate uniqueness of a field named "slug" in a form subclassing django.form.Forms. a. def clean(self): try: Post.objects.get(slug = self.cleaned_data[slug]) raise forms.Error(ValidationError, This slug already exists) except Post.DoesNotExist: return self.cleaned_data b. def clean(self): try: Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com
  • 9. Post.objects.get(slug = self.cleaned_data[slug]) raise ValidationError(This slug already exists) except Post.DoesNotExist: return self.cleaned_datac.def clean_slug(self): try: Post.objects.get(slug = self.cleaned_data[slug]) raise forms.Error(ValidationError, This slug already exists) except Post.DoesNotExist: return self.cleaned_datad.def clean_slug(self): try: Post.objects.get(slug = self.cleaned_data[slug]) raise ValidationError(This slug already exists) except Post.DoesNotExist: return self.cleaned_datae.17. To add custom commands to your project setup, you need to,1. Add management/command/commandname.py to your django app.2. Add management/command/commandname.py to your django project.3. Add command/commandname.py to your django app.4. Add command/commandname.py to your django project.5. Add management/command/manage.py to yout django project. Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com
  • 10. 18.You want to enable caching for Django pages for AnonymousUser, which of theseis a valid way to do this.a.MIDDLEWARE_CLASSES = ( django.middleware.common.CommonMiddleware, django.middleware.cache.CacheMiddleware, django.contrib.sessions.middleware.SessionMiddleware, django.contrib.auth.middleware.AuthenticationMiddleware,)b.MIDDLEWARE_CLASSES = ( django.middleware.common.CommonMiddleware, django.contrib.sessions.middleware.SessionMiddleware, django.middleware.cache.CacheMiddleware, django.contrib.auth.middleware.AuthenticationMiddleware,)c.MIDDLEWARE_CLASSES = ( django.middleware.common.CommonMiddleware, django.contrib.sessions.middleware.SessionMiddleware, django.contrib.auth.middleware.AuthenticationMiddleware, django.middleware.cache.CacheMiddleware,)d.MIDDLEWARE_CLASSES = ( Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com
  • 11. django.middleware.cache.CacheMiddleware, django.middleware.common.CommonMiddleware, django.contrib.sessions.middleware.SessionMiddleware, django.contrib.auth.middleware.AuthenticationMiddleware,)e.MIDDLEWARE_CLASSES = ( django.middleware.cache.CacheMiddleware, django.middleware.common.CommonMiddleware, django.contrib.sessions.middleware.SessionMiddleware,)19.Consider the urlconf given below from django.conf.urls.defaults import * urlpatterns = patterns(news.views, (r^articles/2003/$, year_archive_2003), (r^articles/(d{4})/, year_archive), (r^articles/2003/(d{2})/$, month_archive_2003), (r^articles/(d{4})/(d{2})/, month_archive), (r^articles/(d{4})/10/, month_archive_october), )What view is called when accessing /articles/2003/10/a. year_archive_2003b. year_archivec. month_archive_2003d. month_archivee. month_archive_october Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com
  • 12. 20.Consider the urlpatterns. urlpatterns = patterns(blogapp.views, (r^list/(?P<year>d{4})/(?P<month>[a-z]{3})/$,archive_month), )Which if the following is a valid view function which will be called on accesing/list/2009/jun/a. def archive_month(request): ...b. def archive_month(request, *args):c. def archive_month(request, **kwargs):d. def archive_month(request, year, month,):e. Both c and d# HardNone yet Agiliq Info Solutions India Pvt Ltd, Flat No. 302, Siri Sampada, Above Food World, Near Madhapur Police Station, Hyderabad - 500081. India Phone : 040 – 40186297 Email : hello@agiliq.com

×