Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8814803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:13:14+00:00 2026-06-14T04:13:14+00:00

I am already using a device detection ( http://djangosnippets.org/snippets/2228/ ) in my templates and

  • 0

I am already using a device detection (http://djangosnippets.org/snippets/2228/) in my templates and trying to also make it work in views, so i can redirect to the app store if a user comes from an iPhone.

So I already had:

import re

def mobile(request):

    device = {}

    ua = request.META.get('HTTP_USER_AGENT', '').lower()

    if ua.find("iphone") > 0:
        device['iphone'] = "iphone" + re.search("iphone os (\d)", ua).groups(0)[0]

    if ua.find("ipad") > 0:
        device['ipad'] = "ipad"

    if ua.find("android") > 0:
        device['android'] = "android" + re.search("android (\d\.\d)", ua).groups(0)[0].translate(None, '.')

    # spits out device names for CSS targeting, to be applied to <html> or <body>.
    device['classes'] = " ".join(v for (k,v) in device.items())

    return {'device': device }

And then created a class in tools/middleware.py:

from tools.context_processor import mobile

class detect_device(object):

    def process_request(self, request):
        device = mobile(request)

        request.device = device

Added the following to MIDDLEWARE_CLASSES in the settings.py:

'tools.middleware.detect_device'

And in views.py I created:

def get_link(request):
    if request.device.iphone:
        app_store_link = settings.APP_STORE_LINK
        return HttpResponseRedirect(app_store_link)
    else:
        return HttpResponseRedirect('/')

But I am getting the error:

‘dict’ object has no attribute ‘iphone’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:13:15+00:00Added an answer on June 14, 2026 at 4:13 am

    IT’s a dictionary, not a class.

    Complete view:

    def get_link(request):
        if 'iphone' in request.device['device']:
            app_store_link = settings.APP_STORE_LINK
            return HttpResponseRedirect(app_store_link)
        else:
            return HttpResponseRedirect('/')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I upload my app to app store, I already build my apps using device
Our team is growing, but we're also growing specialized. We've already been using ticketing/bug
I'm trying to communicate to a device using RS-485 through the serial port. Everything
Suppose I already have a bitmap (an image) in Device (Video) Memory using cudaMalloc()
I am already using a basic logging config where all messages across all modules
I am already using the standard way of adding a favicon: <link rel=icon type=image/gif
I am already using output caching in my ASP.NET MVC application. Page speed tells
On Google's website it states: If you're already using the Android SDK, you should
I already attempted using py2exe (not compatible with ipy) and PYC (out of date).
I can already do: using System.Windows.Forms; Button b; or: System.Windows.Forms.Button b; but I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.