Ad
Looks Like A Valid Python Syntax To Me But Gives Me Invalid Error Using In Django
Maybe I'm wrong but this looks like a valid python code to me but I get invalid syntax....I'm trying to split url,removing www when domain is displayed. This is my code:
return urlparse(urlsplit(self.url)).netloc if self.url else "be kind to one another"
but this is wrong... maybe I'm approaching wrong for implementing this function.. any help would be appreciated
Edit 1: Now I get 'SplitResult' object has no attribute 'find'
Ad
Answer
It looks like you just need to delete urlsplit function from your code and it will work as expected:
from urlparse import urlparse
url = "http://stackoverflow.com/questions/34446468/looks-like-a-valid-python-syntax-to-me-but-gives-me-invalid-error-using-in-djang"
long_url = urlparse(url).netloc if url else "be kind to one another"
long_url.split('.', 1)[1] if long_url.split('.', 1)[0] == 'www' else long_url
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad